我正在尝试使用Files.walk api和java8中的相关路径来读取文件列表,而我正在获取java.nio.file.NoSuchFileException:\ src \ main \ resources \ eclipseconftemplates \ java,相同的api正在使用实际路径
获取异常。
try (Stream<Path> paths = Files.walk(Paths.get("/src/main/resources/eclipseconftemplates/java"))) {
paths
.filter(Files::isRegularFile)
.forEach(System.out::println);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
工作正常:
try (Stream<Path> paths = Files.walk(Paths.get("C:\\Users\\XXXX\\maven_project_demo\\antToMaven\\src\\main\\resources\\eclipseconftemplates\\java"))) {
paths
.filter(Files::isRegularFile)
.forEach(System.out::println);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。