java FileFilter的使用
package filterdemo; import java.io.File; import java.io.FileFilter; import java.io.IOException; public class FilterDemo { public static void main(String args[]) throws IOException{ File f = new File("D:\\Temp"); FileFilter ff = new FileFilter() { @Override public boolean accept(File pathname) { // TODO Auto-generated method stub String s = pathname.getName().toLowerCase(); if(s.endsWith(".txt")){ return true; } return false; } }; File[] flist = f.listFiles(ff); if(flist == null){ System.out.println("the flist is null"); return; } for(File fs: flist){ System.out.println(fs); } } }
欢迎访问:wenhao.ink