title: How to make FileFilter in Java?
body: <p>How to make a filter for .txt files?</p>
  <p>I wrote something like this but it has an error:</p>
  <pre><code> private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
          JFileChooser chooser = new JFileChooser();
          int retval = chooser.showOpenDialog(null);
          
          String yourpath = &quot;E:\\Programy Java\\Projekt_SR1\\src\\project_sr1&quot;;
          File directory = new File(yourpath);
          String[] myFiles;
          FilenameFilter filter = new FilenameFilter() {
          public boolean accept(File directory, String fileName) {
              return fileName.endsWith(&quot;.txt&quot;);
          }
          };
          myFiles = directory.list(filter);
  
          
          if(retval == JFileChooser.APPROVE_OPTION)
          {
              File myFile = chooser.getSelectedFile();
          }
  </code></pre>