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);
}
}
使用遞歸,這就是你需要在這裏 –