錯誤的用法
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 釋放資源
錯誤的用法
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 釋放資源
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。