package io;
/*获取指定目录下的文件是否有以.docx结尾的,如果有输出*/
import java.io.File;
import java.io.FilenameFilter;
public class FileNameFilterDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("e:\\");
String[] strArray = file.list(new FilenameFilter(){
public boolean accept(File dir, String name){
return new File(dir,name).isFile() && name.endsWith(".docx");
}
});
for(String f: strArray){
System.out.println(f);
}
}
}
/*
运行结果:
思维.docx
思维与智慧.docx
研究工具.docx
研究生阶段目标.docx
职场.docx
*/
/*获取指定目录下的文件是否有以.docx结尾的,如果有输出*/
import java.io.File;
import java.io.FilenameFilter;
public class FileNameFilterDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("e:\\");
String[] strArray = file.list(new FilenameFilter(){
public boolean accept(File dir, String name){
return new File(dir,name).isFile() && name.endsWith(".docx");
}
});
for(String f: strArray){
System.out.println(f);
}
}
}
/*
运行结果:
思维.docx
思维与智慧.docx
研究工具.docx
研究生阶段目标.docx
职场.docx
*/

本文展示了一个使用Java实现的文件名过滤器示例,该示例能够从指定目录中筛选出所有以.docx为扩展名的文件并打印出来。
1718

被折叠的 条评论
为什么被折叠?



