In the following code:
DataInputStream in = new DataInputStream(
new BufferedInputStream(new FileInputStream(file)));
in.close();
Do I need to close the 2 other stream in addition to closing the "top level" stream?
if you look the source of DataInputStream
you can see that it closes the underlying streams as well. so you don't need. and this is (or should be) true for all type of streams.
I will use this opportunity to answer with an answer I have already made before.
By using Project Lombok you can let Lombok correctly close the streams for you. Details can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With