code: public static File[] findFiles(File dir, FileFilter filter) throws FileNotFoundException {
          if (!dir.exists()) {
              throw new FileNotFoundException("Directory " + dir + " does not exist.");
          }
  
          if (!dir.isDirectory()) {
              throw new FileNotFoundException("File " + dir + " is not a directory.");
          }
  
          // being matching process, create array for returning results
          ArrayList<File> files = new ArrayList<File>();
  
          // get all files in this directory
          File[] allFiles = dir.listFiles();
  
          // were any files returned?
          if (allFiles != null && allFiles.length > 0) {
              // loop thru every file in the dir
              for (File f : allFiles) {
                  // only match files, not a directory
                  if (f.isFile()) {
                      // delegate matching to provided file matcher
                      if (filter.accept(f)) {
                          files.add(f);
                      }
                  }
              }
          }
  
          // based on filesystem, order of files not guaranteed -- sort now
          File[] r = files.toArray(new File[0]);
          Arrays.sort(r);
          return r;
      }
docs: Finds all files (non-recursively) in a directory based on the FileFilter.
  This method is slightly different than the JDK File.listFiles() version
  since it throws an error if the directory does not exist or is not a
  directory.  Also, this method only finds files and will skip including
  directories.