List file with file filter : FileFilter « File « Java Tutorial


public class MainClass {

  public static void main(String[] args) {

    File cwd = new File(System.getProperty("user.dir"));
    File[] htmlFiles = cwd.listFiles(new HTMLFileFilter());
    for (int i = 0; i < htmlFiles.length; i++) {

class HTMLFileFilter implements FileFilter {

  public boolean accept(File pathname) {

    if (pathname.getName().endsWith(".html"))
      return true;
    if (pathname.getName().endsWith(".htm"))
      return true;
    return false;

11.72.1.Create custom File filter
11.72.2.List file with file filter
11.72.3.Custom File Filter
11.72.4.Filter by file
11.72.5.This filter accepts Files that are directories
11.72.6.Filters files based on the extension (what the filename ends with)
11.72.7.Inverted File Filter
11.72.8.Files filter that filters files by their suffix (or extension)
11.72.9.Generic File Filter
11.72.10.A suffix based file filter.