This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes Does closing a stream, close the enclosed stream as well? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Does closing a stream, close the enclosed stream as well?" Watch "Does closing a stream, close the enclosed stream as well?" New topic
Author

Does closing a stream, close the enclosed stream as well?

Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Hi
I had a trivial question. Does closing a stream, close the enclosed stream as well?
For e.g., if I have a BufferedInputStream which encloses a FileInputStream, then does closing BufferedInputStream take care of closing FileInputStream as well?


Thanks and Regards
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

It depends on the InputStream class*, but in general: yes.

* you can subclass FilterInputStream to make close do nothing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Thanks Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does closing a stream, close the enclosed stream as well?