【发布时间】:2016-05-23 06:10:25
【问题描述】:
尽管我已经看到很多类似问题的答案,但我无法让以下代码按我认为的那样工作:
File dataDir = new File("C:\\User\\user_id");
PathMatcher pathMatcher = FileSystems.getDefault()
.getPathMatcher("glob:" + "**\\somefile.xml");
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(
dataDir.toPath(), pathMatcher::matches)) {
Iterator<Path> itStream = dirStream.iterator();
while(itStream.hasNext()) {
Path resultPath = itStream.next();
}
} catch (IOException e) {...
我希望获得 C:\User\user_id 下所有“somefile.xml”的路径列表及其下方的所有子目录。然而 hasNext() 方法每次都返回 false。
【问题讨论】: