13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java Input and Output}This code requires some explanation. The idea is that we keep track of all streamscreated. If they cannot be created successfully, their variables will still be null sowe won't try to close them. At the end of the I/O operations (in the finally block)we check each stream and try to close() it. If the close() succeeds, it has alsoclosed any delegate steams, so we set their variables to null as well. If theclose() fails, the delegate streams will still be non-null and we will attempt toclose them in the next block. Of course the order of the closing is extremelyimportant.One final note: the action to take when a close() fails is completely up to yourapplication design. If the data is important, you should definitely inform the userthat there was a problem closing the file. If the data was not important, it may beok to simply ignore the error as we do in the above example.[MML: 1.03][Version: $ /JavaIO/JavaIO.mml#7 $]Java Input and Output -62© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!