/**
*
* @param strPath
* @return
*/
public List<File> getFileList(String strPath) {
List<File> filelist = new ArrayList<>();
File dir = new File(strPath);
File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
if (files != null) {
for (int i = 0; i < files.length; i++) {
String fileName = files[i].getName();
if (files[i].isDirectory()) {
getFileList(files[i].getAbsolutePath()); //遍历子文件夹里面的东西
} else if (fileName.endsWith("exe")) { // 以***结尾的文件
String strFileName = files[i].getAbsolutePath();
filelist.add(files[i]);
} else {
filelist.add(files[i]);
continue;
}
}
}
return filelist;
}
@Test
public void t2() {
String strPath = "D:\\360极速浏览器下载";
System.err.println(getFileList(strPath));
}