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

Answer:


End of File

DataInputStream  instr;
DataOutputStream outstr;
. . . .
try
{
  int data;
  while ( true )
  {
    data = instr.readUnsignedByte() ;
    outstr.writeByte( data ) ;
  }
}

catch ( EOFException  eof )
{
  outstr.close();
  instr.close();
  return;
}

This loop is the familiar read-until-end-of-file idea which is best done using try{} and catch{} blocks.

Almost all of the program is here, but there are more details to handle. The one-byte-at-a-time nature of the loop is not efficient.


QUESTION 17:

How (in general) can I/O be made more efficient in this program?


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