With generics the same interface can be used for other types of paths. As shown in the following (simplified) code fragment, the interface works nice with java.io.File
:
FileVisitResult walk(File file, FileVisitor<File> visitor)
throws IOException
{
if (file.isDirectory()) {
visitor.preVisitDirectory(file, null);
for (File child : file.listFiles()) {
walk(child, visitor);
}
return visitor.postVisitDirectory(file, null);
} else {
return visitor.visitFile(file, null);
}
}