File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Elasticsearch in Action this week in the Big Data 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: 19908
    
  23

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
 
Don't get me started about those stupid light bulbs.
 
subject: Does closing a stream, close the enclosed stream as well?