How to properly close a BufferedInputStream

410 Views Asked by At

I create a BufferedInputStream from an InputStream. I can close the BufferedInputStream by calling its close() method. Should I also close the InputStream from which it was created, or does that happen sutomatically?

1

There are 1 best solutions below

0
f.loris On BEST ANSWER

Closing BufferedInputStream is sufficient since it closes the underlying stream as well.

This can also be seen in the implementation: https://github.com/openjdk/jdk/blob/9a7209ef346e4f78b6153e998ecdfac72edc5580/src/java.base/share/classes/java/io/BufferedInputStream.java#L482