我正在尝试编写一种方法,该方法从给定目录中提取每个文件(也在每个子目录中)。我正在为此使用 Files.find。问题是,每当它找到我无法访问的文件时,它就会停止,但我想继续研究并将其他文件添加到列表中。这是我的代码
public static List<String> search(String dir){
List<String> listFiles = new ArrayList<>();
try{
Files.find(Paths.get(dir), Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
.forEach((file) -> {
listFiles.add(file.toAbsolutePath().toString());
});
} catch (UncheckedIOException ue){
System.out.println("Can't access that directory");
} catch (IOException e) {
e.printStackTrace();
}
return listFiles;
}
我怎样才能改变它?