A call to ClassLoader.getSystemResourceAsStream opens an input stream to the underlying resource that gets eventually converted into properties:
Properties build = new Properties();
build.load(ClassLoader.getSystemResourceAsStream(ANT_BUILD));
Do we need to explicitly close the stream after loading the properties?
Had a quick look at java.util.Properties and it doesn’t close the stream!
Default
ClassLoader.getSystemResourceAsStream(String)returns aFileInputStreamwrapped intoBufferedInputStream.If you look into FileInputStream sources you will see that it has got
finalizemethod which closes the stream for you.But of course it’s not a good practice to wait for the heap to grow until garbage collector starts to take care of your streams, and you should always try to close streams yourself.