public static void main(String[] args) {
readAllFile("C:\\Users\\73G9Y\\Desktop\\测试");
}
public static void readAllFile(String filepath) {
File file= new File(filepath);
if(!file.isDirectory()){
if(file.getName().indexOf(".docx") > 0){
System.out.println(file.getName());
}
}else if(file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filepath);
if (!readfile.isDirectory()) {
if(file.getName().indexOf(".docx") > 0){
System.out.println(file.getName());
}
System.out.println(file.getName());
} else if (readfile.isDirectory()) {
readAllFile(filepath + "\\" + filelist[i]);//递归
}
}
}
}
12-22