如何在 Java 8 中从多个路径搜索文件。这些不是子/同级目录。例如,如果我想搜索路径中的 json 文件,我有:
try (Stream<Path> stream = Files.find(Paths.get(path), Integer.MAX_VALUE, (p, attrs) -> attrs.isRegularFile() && p.toString().endsWith(".json"))) {
stream.map((p) -> p.name).forEach(System.out::println);
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法在多个路径中搜索?或者我是否必须为多个路径运行相同的代码?