java - Does collect operation on Stream close the stream and underlying resources? -


does below code need wrapped in try-with-resources make sure underlying file closed?

list<string> rows = files.lines(inputfilepath).collect(collectors.tolist()); 

as javadoc of overloaded files#lines(path, charset) method states

the returned stream encapsulates reader. if timely disposal of file system resources required, try-with-resources construct should used ensure stream's close method invoked after stream operations completed.

so yes, wrap stream returned lines in try-with-resources statement. (or close appropriately.)


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -