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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World