采用递归的方式,逐层读取目录下的文件
public void getFile(String path, List<String> fileList) {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
for (File subFile : files) {
getFile(subFile.getPath(), fileList);
}
}
} else {
fileList.add(file.getAbsolutePath());
}
}
原文地址:https://www.cnblogs.com/tulip20/p/12305407.html
时间: 2024-11-10 10:49:52