Opening the Files
The constructors for FileInputStream
and for FileOutputStream throw exceptions
which need to be caught.
This calls for an outer try{} block:
DataInputStream instr;
DataOutputStream outstr;
. . . .
try
{
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 outer try{} block encloses the constructors and the
IO loop.
|