错误的用法
Files.list(directory).forEach(path -> { // do });
正确的用法
try (Stream<Path> stream = Files.list(directory)) { stream.forEach(path -> { // do }); } catch (Exception e) { //e.printStackTrace(); }
使用 try-with-resources 释放资源