• Post Reply Bookmark Topic Watch Topic
  • New Topic

When is an explicit close() necessary?

 
Paul Ramsden
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When must a stream be explicity closed?

Consider


Does this need to be closed?

What about


I think the first example is safe - the close will be done on finalize.
The second example does need a close.

Am I wrong?
 
Rob Spoor
Sheriff
Posts: 20816
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The safest is to always close all your streams and readers, regardless what the source is. If a stream or reader doesn't need to do anything it will do nothing, but should you ever change the source of the stream / reader you will be happy you added the close now.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!