import java.io.*;

    // Illustrate the FileInputStream and FileOutputStream classes
    // by making a binary copy of the command line argument in the
    // file output.bin.
class StreamExampleMain {
        // Any Exceptions caused program termination.
    public static void main(String[] args)
                        throws FileNotFoundException, IOException {
        if(args.length == 1){
            final String outputFile = "output.bin";
            FileInputStream inFile = new FileInputStream(args[0]);
            FileOutputStream outFile = new FileOutputStream(outputFile);
            // Provide space for a small number of bytes to be read.
            final int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];
            // Read the first chunk of bytes.
            int numberRead = inFile.read(buffer);
            // Keep going as long as something was read.
            while(numberRead > 0){
                // Write out what was read.
                outFile.write(buffer,0,numberRead);
                // Read the next chunk, if any.
                numberRead = inFile.read(buffer);
            }
            inFile.close();
            outFile.close();
        }
        else{
            System.err.println("Usage: java StreamExampleMain binary-file");
        }
    }
}
