I have a directory with huge number of files,I need to list all the files from that directory with a particular word on it's name,like India or else. Also how to get the path of that files?
Something like this should work:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.