/*文件名称过滤器的概述
* public String[] list(FilenameFilter filter)
* public File[] listFiles(FileFilter filter)
* B:文件名称过滤器的使用*/
//判断E盘目录下是否有后缀名为.txt的文件,如果有,就输出该文件名称
public class Demo3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
File f = new File("E:\\");
String[] s = f.list(new FilenameFilter(){
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
File file = new File(dir,name);
return file.isFile()&&file.getName().endsWith(".txt");
}
});
for (String string : s) {
System.out.println(string);
}
}