This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  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?
 
Similar Threads
Will close one of three linked streams close them all?
Slow Swing FTP Problem
Download File
Testing for close() inside loop
Procuing Output to a text file is showing peculier behaviour