Java FileFilter create via Lambda

Description

Java FileFilter create via Lambda

import java.io.File;
import java.io.FileFilter;

public class Main {
  public static void main(String[] args) {
    String dirPath = "E:/Java_Dev";
    File dir = new File(dirPath);
    FileFilter filter = file -> {
      if (file.isFile()) {
        String fileName = file.getName().toLowerCase();
        if (fileName.endsWith(".java")) {
          return false;
        }/*from   w  w  w  . j a  va  2 s.  c  om*/
      }
      return true;
    };

    File[] list = dir.listFiles(filter);

    for (File f : list) {
       System.out.println(f.getPath());
    }
  }
}



PreviousNext

Related