DirectoryStream with PathMatcher not returning any paths

后端 未结 1 824
清酒与你
清酒与你 2021-01-26 19:21

Although I\'ve seen a lot of answers for similar questions I can\'t make the following code work as I think it should:

File dataDir = new File(\"C:\\\\User\\\\us         


        
相关标签:
1条回答
  • 2021-01-26 19:56

    DirectoryStream only iterates through the directory you give it and matches entries in that directory. It does not look in any sub-directories.

    You need to use one of the walkXXXX methods of Files to look in all directories. For example:

    try (Stream<Path> stream = Files.walk(dataDir.toPath())) {
      stream.filter(pathMatcher::matches)
            .forEach(path -> System.out.println(path.toString()));
    }
    
    0 讨论(0)
提交回复
热议问题