FilenameFilter

  FilenameFilter接口用于过滤目录列表。例子如下:
public class DirList {

public static FilenameFilter filter(final String regex) {
return new FilenameFilter() {

public boolean accept(File dir, String name) {
return name.indexOf(regex) != -1;
}
};
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File path = new File("e:/");
String[] list = path.list();
for(int i = 0; i < list.length; i++)
System.out.println(list[i]);
System.out.println("----------------------");
list = path.list(filter(".out"));
for(int i = 0; i < list.length; i++)
System.out.println(list[i]);
}
}

你可能感兴趣的:(FilenameFilter)