Reading Data from a File

This chapter discusses Java's FileReader and BufferedReader classes in detail. FileReader and BufferedReader classes are used together when reading data from an external file. The use of the BufferedReader class allows data to be buffered as it is read from a file before manipulating it. The readLine() method of the BufferedReader class reads a line of text from a character-oriented input stream, and puts it into a new String object.

11. Closing Files


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?