package Files;
import java.io.IOException;
import java.nio.file.*;
public class TestFilesDir
{
TestFilesDir()
{
}
public void iteratorDir(Path dir) throws IOException
{
try (DirectoryStream<Path> entries = Files.newDirectoryStream(dir))
{
for (Path enPath : entries)
{
if (Files.isDirectory(enPath))
{
if(enPath.endsWith("System Volume Information") == true)
{
continue;
}
System.out.println("this is dir and dir name is "
+ enPath.getFileName());
System.out.println("I include:");
System.out.println("{");
this.iteratorDir(enPath);
}
else
{
System.out.println("this is file and file name is"
+ enPath.getFileName());
System.out
.println("------------------------------------------------");
}
}
System.out.println("}");
}
}
import java.io.IOException;
import java.nio.file.*;
public class TestFilesDir
{
TestFilesDir()
{
}
public void iteratorDir(Path dir) throws IOException
{
try (DirectoryStream<Path> entries = Files.newDirectoryStream(dir))
{
for (Path enPath : entries)
{
if (Files.isDirectory(enPath))
{
if(enPath.endsWith("System Volume Information") == true)
{
continue;
}
System.out.println("this is dir and dir name is "
+ enPath.getFileName());
System.out.println("I include:");
System.out.println("{");
this.iteratorDir(enPath);
}
else
{
System.out.println("this is file and file name is"
+ enPath.getFileName());
System.out
.println("------------------------------------------------");
}
}
System.out.println("}");
}
}
}
想办法获得系统文件的权限或者避开系统文件才是