我的目录中包含大量文件,我需要列出该目录中的所有文件,并在其名称上加上特定的单词,例如印度或其他。还有如何获取该文件的路径?
类似这样的方法应该起作用:
try (Stream<Path> paths = Files.walk(Paths.get("/home/you/Desktop"))) {
paths
.filter(Files::isRegularFile)
// You can also use Apache StringUtils.containsIgnoreCase()
.filter(path -> path.getFileName().toString().toLowerCase().contains(word.toLowerCase()))
.forEach(System.out::println);
}