title: Non-recursive way to get all files in a directory and its subdirectories in Java
body: <p>I am trying to get a list of all files in a directory and its subdirectories. My current recursive approach is as follows:</p>
  
  <pre><code>private void printFiles(File dir) {
    for (File child : dir.listFiles()) {
      if (child.isDirectory()) {
        printFiles(child);
      } else if (child.isFile()) {
        System.out.println(child.getPath());
      }
    }
  }
  
  printFiles(new File("somedir/somedir2"));
  </code></pre>
  
  <p>However, I was hoping there was a non-recursive way (an existing API call, maybe) of doing this. If not, is this the cleanest way of doing this?</p>