go to previous page   go to home page   go to next page

Answer:

By using buffered input and buffered output.


Buffering


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;
}

BufferedInputStream and BufferedOutputStream each put a buffer between the program and the disk. The program logic deals with single bytes. However, by using these classes, the actual I/O is done more efficiently.

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).


QUESTION 18:

But now there is something else that needs to be handled. What is it?


go to previous page   go to home page   go to next page