Blog

Files.lines() の返り値は try-with-resources で閉じる

Files.lines は閉じていない BufferedReader を Stream に詰め込んで返すので、try-with-resources で閉じる必要がある。

    The returned stream encapsulates a Reader. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed.

https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#lines-java.nio.file.Path-java.nio.charset.Charset-

ref. http://mike-neck.hatenadiary.com/entry/2015/04/12/210000