Using a FileWalker
Start at the root; list all files; watch out for links
import java.nio.filesystems.*;
import java.io.*;
public class FileSystemLister {
public static void main(String[] args) throws IOException {
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++) {
FileReference ref = roots[i].toFileReference();
Files.walkFileTree(ref, false, new NamePrinter());
}
}
class NamePrinter implements FileVisitor {
void visit(FileReference file, Path path, BasicFileAttributes attrs) {
System.out.println(path.getName());
}
void visit(FileReference file, Path path, IOException ex) {
System.err.println(ex.getMessage());
}
}
}