My code is:
InputStream confFile=classLoader.getResourceAsStream("myconffile.properties");
In docs:
The close method of InputStream does nothing.
Does it mean that I don't need close InputStream?
You don't have to close ByteArrayInputStream , the moment it is not referenced by any variable, garbage collector will release the stream and somebytes (of course assuming they aren't referenced somewhere else).
An FileInputStream and a BufferedInputStream . Both of these resources will be closed automatically when execution leaves the try block.
You do need to close the input Stream, because the stream returned by the method you mention is actually FileInputStream or some other subclass of InputStream
that holds a handle for a file. If you do not close this stream you have resource leakage.
No, it does not mean that - because InputStream
is an abstract class, and getResourceAsStream()
returns a concrete subclass whose close()
method does something - most importantly free a file handle.
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