Does below code need to be wrapped in try-with-resources to make sure underlying file is closed?
List rows = Files.lines(inputFilePath).collect
As the javadoc of the overloaded Files#lines(Path, Charset) method states
The returned stream encapsulates a
Reader
. If timely disposal of file system resources is required, thetry-with-resources
construct should be used to ensure that the stream's close method is invoked after the stream operations are completed.
So yes, wrap the Stream
returned by lines
in a try-with-resources
statement. (Or close it appropriately.)