Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Do you have to close all streams of a nested set of streams?

807591Apr 18 2008 — edited Apr 18 2008
In the following example, which of the streams needs to be closed?
OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
...
osw.close();
Closing the OutputStreamWriter causes the data to be flushed, but do you have to close the other 2 streams? Are they still open? What about the FileOutputStream, there's not variable assigned to that, does it have to be closed as well as the BOS?
Thanks
Antony
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2008
Added on Apr 18 2008
6 comments
684 views