Reading Data from a File
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 itsIOException
s?