ignore exception and continue & counting files in a directory
问题 The following snippet of code counts the number of files in a directory: Path path = ...; .... long count = 0; try { count = Files.walk(path).parallel().filter(p -> !Files.isDirectory(p)).count(); } catch (IOException ex) { System.out.println(ex.getMessage()); } The code above fails to get the number of files, if an exception is thrown. The question is: How do I ignore the exception and continue counting the number of files. In Java 7 : I have used Files.walkFileTree(path, utils) , with the