This is my first time working with Files.walk in Java, and I rather like it, especially the Path class. It's robust and versatile.
What I'm not liking, however, is that when walking a folder, if the iterator runs into a snag ... like it hits a folder that the user does not have permission to see or whatever error it might encounter, after it throws the exception, it doesn't continue nor does it yield a list of paths to work with.
Here is an example of how I'm using the method:
try {
Stream<Path> paths = Files.walk(rootPath);
List<Path> pathList = paths.collect(Collectors.toList());
for (Path path : pathList) {
//Processing code here
}
}
catch (FileSystemException a) {System.err.format("FileSystemException: %s%n", a);System.out.println(a.getStackTrace());}
catch (UncheckedIOException b) {System.err.format("UncheckedIOException: %s%n", b);System.out.println(b.getCause().getLocalizedMessage());}
catch (IOException c) { System.err.format("IOException: %s%n", c);System.out.println(c.getStackTrace());}
Now, if the Files.walk method encounters some kind of error while trying to iterate through the folders, it throws the exception and then of course the code continues after catching the exception.
What I WANT it to do is to ignore any problems it encounters and to just continue to iterate through whatever folders it can without ever stopping.
Is this possible?