【发布时间】:2018-07-11 20:02:04
【问题描述】:
我在 SpringBoot 应用的资源文件夹中有这个文件夹。
resources/files/a.txt
resources/files/b/b1.txt
resources/files/b/b2.txt
resources/files/c/c1.txt
resources/files/c/c2.txt
我想获取所有的 txt 文件,所以这是我的代码:
ClassLoader classLoader = this.getClass().getClassLoader();
Path configFilePath = Paths.get(classLoader.getResource("files").toURI());
List<Path> atrackFileNames = Files.list(configFilePath)
.filter(s -> s.toString().endsWith(".txt"))
.map(Path::getFileName)
.sorted()
.collect(toList());
但我只得到文件 a.txt
【问题讨论】:
标签: java collections java-8 functional-programming stream