SimpleFileVisitor approach:
In order to use SimpleFileVisitor you can use walkFileTree
in the following way:
try {
Files.walkFileTree(Paths.get("somePath"), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
System.out.println("visitFile: " + file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException ex) throws IOException {
System.out.println("visitFileFailed: " + file + " because of " + ex);
return FileVisitResult.CONTINUE;
}
// etc... you can add postVisit...
});
} catch (IOException e) {
...
}
This lets you to perform actions while visiting each file, but it has nothing to do with streams (well stream is a tool that you should use when it fits your needs, do not force yourself to use it when not convenient)
Stream approach:
If you prefer walk & stream you can do the following:
Stream<Path> files = Files.walk(Paths.get("somePath")).forEach(path -> doSomethingWithPath(path));
Not sure why you need SimpleFileVisitor here,as your explanation:
because it is needed
is pretty mysterious ;)