title: Do terminal operations on streams close the source?
body: <p>Consider the following code:</p>
  
  <pre><code>Path directory = Paths.get(/* some directory */);
  Files.list(directory).forEach(System.out::println);
  </code></pre>
  
  <p>Does a terminal operation (like <code>forEach</code>) close the underlying file that has been opened?</p>
  
  <p>Refer to the relevant parts of the javadoc of <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#list-java.nio.file.Path-" rel="noreferrer">Files.list</a>:</p>
  
  <blockquote>
    <p>The returned stream encapsulates a DirectoryStream. 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. </p>
  </blockquote>
  
  <p>If it doesn't call <code>Stream.close()</code>, what would then be the best alternative to call it while producing maintainable code?</p>