import java.io.*;

/***************************************************************************

    Split -- Split a Large File into Segments That Will Each Fit on a Floppy

    This copies a large file into a number of smaller segment files.  Each
    segment file can fit on a floppy disk and each one has a file extension
    like .1 or .2.  This utility can be very helpful for moving large files
    like the JDK to a machine without an Internet connection.  

    To reassemble the files, copy all the segments to a hard disk then
    perform a binary appended copy:

      copy /b myfile.1+myfile.2+myfile.3 myfile

    Invoking this application from the command line without parameters 
    gives the syntax.

 ***************************************************************************/   

    class Split
      { 
      public static void main (String args[]) 
        {
        int iBufferSize = 1400000;
        File fIn;
        FileInputStream fisIn;
        File fOut;
        FileOutputStream fosOut;
        byte[] ab = new byte[iBufferSize];
        int iNumRead = iBufferSize;
        int i;
        String sInFileName;
        String sInFileExtension;
        String sOutFileName;
        String sOutFileExtension;

        if (args.length < 3)
          {
          System.out.println ("format: java Split InFileName InExtensionName "
            + "OutFileName");
          System.exit (1);
          }
        sInFileName = args[0];
        sInFileExtension = args[1];
        sOutFileName = args[2];

        try
          {
          fIn = new File (".", sInFileName + "." + sInFileExtension);
          fisIn = new FileInputStream (fIn);
          i = 1;

          while (iNumRead == iBufferSize)
            {
            sOutFileExtension = "." + i;
            fOut = new File (".", sOutFileName + sOutFileExtension);
            fosOut = new FileOutputStream (fOut);

            iNumRead = fisIn.read (ab);
            System.out.println ("writing " + iNumRead + " bytes...");
            fosOut.write (ab, 0, iNumRead);
            fosOut.close ();
            i++;
            }
          fisIn.close ();
          }
        catch (Exception e)
          {
          System.out.println ("Error: " + e);
          }

        System.out.println ("Done!");
        }
      } 

