This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Closing a file" Watch "Closing a file" New topic

Closing a file

marlon tan
Ranch Hand

Joined: Feb 18, 2001
Posts: 53

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

Joined: Jul 08, 2003
Posts: 24193

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]
I agree. Here's the link:
subject: Closing a file
It's not a secret anymore!