Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing a file

 
marlon tan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "wrapper" classes like BufferedWriter pass the close() call along to the "wrapped" object -- so calling upper.close() automatically calls lower.close() as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic