title: How to list all text files in a directory
body: <p>I tried to write the following code, but it does not work.</p>
  
  <pre><code>public File[] finder(String dirName) {
      File dir = new File(dirName);
  
      return dir.listFiles(new FilenameFilter() {
          @Override
          public boolean accept(File dir, String filename) {
              return filename.endsWith(".txt");
          }
      });
  }
  </code></pre>