上代码:
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Main
{
public static void main(String[] args) {
String rootRepoPath = "C:\\Users\\graces\\.m2\\repository";
searchPomFile(rootRepoPath);
}
public static void searchPomFile(String rootRepoPath) {
List<String> pomFileList = new ArrayList<>();
listFolder(new File(rootRepoPath), pomFileList);
pomFileList.stream().forEach(x -> System.out.println(x));
}
public static void listFolder(File folder, List<String> pomFileList) {
for (File file:
folder.listFiles()) {
if (file.isDirectory()) {
listFolder(file, pomFileList);
} else {
if (file.getName().endsWith(".pom")) {
pomFileList.add(file.getAbsoluteFile().getAbsolutePath());
}
}
}
}
}