-1

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?

Shanto George
  • 994
  • 13
  • 26
  • You can write your own `FileFilter` - in particular, you'll place your implementation when you @Override `accept()` – sleepToken Jan 21 '20 at 16:36
  • https://docs.oracle.com/javase/8/docs/api/java/io/File.html#listFiles-java.io.FilenameFilter- – JB Nizet Jan 21 '20 at 16:36

1 Answers1

2

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);
}