获取文件夹下的所有子文件,读取TXT文档

  1. /**child.toString().matches(".+\\.txt")

* 递归读取文件路径下的所有文件
*
* @param path
* @param fileNameList
* @return
*/
public static ArrayList<String> readFiles1(String path, ArrayList<String> fileNameList) {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
readFiles1(files[i].getPath(), fileNameList);
} else {
String path1 = files[i].getPath();
String fileName = path1.substring(path1.lastIndexOf("\\") + 1);
fileNameList.add(fileName);
}
}
} else {
String path1 = file.getPath();
String fileName = path1.substring(path1.lastIndexOf("\\") + 1);
fileNameList.add(fileName);
}
return fileNameList;
}

posted @ 2019-08-16 15:57  Jack-Huang  阅读(696)  评论(0编辑  收藏  举报