aspose 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
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: 19792
    
  20

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?