目录
1 代码实现
代码语言:javascript
复制 /**
* 递归读取文件路径下的所有文件
*
* @param path
* @param fileNameList
* @return
*/
public static ArrayList<String> readFiles(String path, ArrayList<String> fileNameList, Pattern pattern) {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i ) {
if (files[i].isDirectory()) {
readFiles(files[i].getPath(), fileNameList,pattern);
} else {
String path1 = files[i].getName();
if(pattern.matcher(path1).find()){
fileNameList.add(files[i].getPath());
}
}
}
} else {
String path1 = file.getName();
if(pattern.matcher(path1).find()){
fileNameList.add(file.getPath());
}
}
return fileNameList;
}