package com.cmy.niobiocio;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class B {
public static void main(String []args){
findCDirectoryTree();
}
public static void findCDirectoryTree(){
Path p1=FileSystems.getDefault().getPath("D://");
try {
Files.walkFileTree(p1,new SimpleFileVisitor(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// TODO Auto-generated method stub
if(file.toString().endsWith(".txt")){
System.out.println(file.getFileName());
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行结果如下:
java.nio.file.AccessDeniedException: D:\$RECYCLE.BIN\S-1-5-21-4206971208-3045675379-530765779-1002
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsDirectoryStream.(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(Unknown Source)
at java.nio.file.Files.newDirectoryStream(Unknown Source)
at java.nio.file.FileTreeWalker.walk(Unknown Source)
at java.nio.file.FileTreeWalker.walk(Unknown Source)
at java.nio.file.FileTreeWalker.walk(Unknown Source)
at java.nio.file.FileTreeWalker.walk(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at com.cmy.niobiocio.B.findCDirectoryTree(B.java:20)
at com.cmy.niobiocio.B.main(B.java:15)
出现了以上错误,求各位大神指点一下