title: List all files from a directory recursively with Java
body: <p>I have this function that prints the name of all the files in a directory recursively. The problem is that my code is very slow because it has to access a remote network device with every iteration.</p>
  <p>My plan is to first load all the files from the directory recursively and then after that go through all files with the regex to filter out all the files I don't want. Does anyone have a better suggestion?</p>
  <pre class="lang-java prettyprint-override"><code>public static printFnames(String sDir) {
      File[] faFiles = new File(sDir).listFiles();
      for (File file : faFiles) {
          if (file.getName().matches(&quot;^(.*?)&quot;)) {
              System.out.println(file.getAbsolutePath());
          }
          if (file.isDirectory()) {
              printFnames(file.getAbsolutePath());
          }
      }
  }
  </code></pre>
  <p>This is just a test later on I'm not going to use the code like this, instead I'm going to add the path and modification date of every file which matches an advanced regex to an array.</p>