wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Closing a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Closing a file" Watch "Closing a file" New topic
Author

Closing a file

marlon tan
Ranch Hand

Joined: Feb 18, 2001
Posts: 53
Hi,

In using Java IO classes, you often wrap lower level input/output stream to a higher level one. For example,



What's the appropriate way of closing the file, do you close the file using
lower.close() or higher.close(), or both?

Thank you.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The "wrapper" classes like BufferedWriter pass the close() call along to the "wrapped" object -- so calling upper.close() automatically calls lower.close() as well.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Closing a file
 
Similar Threads
How to parse an XML document containing Chinese characters and get an XML bean
Couldn't move file just created earlier in the same program
Writing to a directory in a Unix environment
Trouble appending new data to an existing file
Opening files in append mode