title: Is is possible to list file characteristics from .forEach method?
body: <p>I'm trying to use more Java 8 syntax. I have a simple use case here, listing files recursively, where I'd like to print more than just the file name as the example shows:</p>
  
  <pre><code>public void listFiles(String path) {
      try {
          Files.walk(Paths.get(path))
               .filter(p -&gt; {
                   return Files.isRegularFile(p);
               })
                .forEach(System.out::println);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Is there a way to call a method from the forEach method, passing the file in question as a parameter? How would I reference the file? </p>
  
  <p>Edit: There was some confusion in the discussion about whether the path of each file being printed could be passed as a variable to another method. </p>
  
  <p>To confirm, it can. Here's the code:</p>
  
  <pre><code> public void listFiles(String path) {
          try {
              Files.walk(Paths.get(path))
                      .filter(p -&gt; {
                          return Files.isRegularFile(p);
                      })
                      .forEach(p -&gt; myMethod(p));
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private void myMethod(Path path) {
          System.out.println(path.toAbsolutePath());
          try {
              BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
              FileTime fileTime = attr.lastModifiedTime();
              System.out.println("file date: " + fileTime);
          } catch (IOException ex) {
              // handle exception
          }
      }
  </code></pre>