By using buffered input and buffered output.
The stream types BufferedInputStream
and BufferedOutputStream
each put a buffer between the program and the disk.
The program logic deals with single bytes.
However, the
actual IO is done more efficiently.
DataInputStream instr; DataOutputStream outstr; . . . . instr = new DataInputStream( new BufferedInputStream( new FileInputStream( args[0] ))); outstr = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( args[2] ))); try { int data; while ( true ) { data = instr.readUnsignedByte() ; outstr.writeByte( data ) ; } } catch ( EOFException eof ) { outstr.close(); instr.close(); return; }
The names of the files come from the command line. The name of the file to be copied is argument number 0; the copy is argument number 2 (the word "to" is argument number 1).
But now there is something else that needs to be handled. What is it?