I have this simple code that processes files in a designated folder.
processLog
method throws IOException, when this happens I would like to exit (no need to continue processing rest of the files) but sadly I have to catch the exception locally.
try (Stream<Path> filePathStream = Files.walk(Paths.get(logs))){
filePathStream.forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
processLog(filePath.toFile());
}
});
}
Any idea how I can break the loop? Thanks.