title: How can you in Java list all files recursively in a folder that do not match an array of extensions?
body: <p>I have a simple program that I am making that looks through a directory recursively and removes all files that do not match the files extensions chosen by the user. (essentially I am remaking a script that I wrote in PHP to help teach myself java)</p>
  
  <p>The method works fine except that it returns an array of files that match the array of extensions. This would remove the wrong files. How can I return the files that do not match?</p>
  
  <p>I am using org.apache.commons.io.FileUtils with a string array to get the files:</p>
  
  <pre><code>import java.io.File;
  import java.util.List;
  import java.io.IOException;
  import org.apache.commons.io.FileUtils;
  
  public class Recurse {
  // The method that takes a directory path (file object called folder) and a string of extensions
      public static List&lt;File&gt; getFiles(final File folder, String[] extensions) throws IOException{
  
      List&lt;File&gt; fileList = (List&lt;File&gt;) FileUtils.listFiles(folder, extensions, true);
  
      return fileList;
      }
  }
  </code></pre>
  
  <p>I have found examples that use just one file type e.g ".txt" but cannot find one for an array. I would prefer to stick with org.apache.commons.io.FileUtils but I am willing to change my method.</p>