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
Post a Comment