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

Answer:

Click!


Closing Files

Here is the file closing method. It is possible (though rare) for closing a file to fail. The close() method of PrintWriter does not throw an exception.

class CopyMaker
{
   String sourceName, destName;
   BufferedReader source;
   PrintWriter dest;
   String line;

   private void closeFiles() 
   {
     // close the source
     try
     {      
       source.();
     }
     catch ( IOException iox )
     {
       System.out.println("Problem closing " +);
     }

     // close the destination
     dest.();
   }

    . . . . .  the rest of the program . . . . .
   
}

QUESTION 11:

Since errors on closing a file are rare, would it be OK to have closeFiles() throw its IOExceptions?