0
我想遍历一个文件夹listFiles不返回文件,但
我的文件位于
D:\PROJECT_FOLDER\rootProject\semiRootProject\project\build\resources\main\com\xxxx\pack\file.xlsx
然而,当我尝试遍历它在控制台只是顶层文件夹它显示
11:39:06.731 [main] INFO com.xxxx.util.KiePackageCreator - File found: D:\PROJECT_FOLDER\rootProject\semiRootProject\project\build\resources\main\com.
什么问题?我的搜索循环看起来像这样。
File fileFolder = new File(projectBuildDir + RESOURCE_SUBFOLDER);
for (File file : fileFolder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
//if (name.endsWith(".xlsx")) {
return true;
//}
//return false;
}
})) {
LOGGER.info("File found: {}.", file.toPath());
if (file.isFile()) {
Resource fileResource = getClassPathResource(file.getName());
String filePath = file.getPath();
String rulePath = MAVEN_RESOURCE_PATH + filePath.substring(filePath.indexOf("com"));
LOGGER.info("Attempt to write into: {}.", rulePath);
kfs.write(rulePath, fileResource);
}
}
使用递归,这就是你需要在这里 –