1. 程式人生 > >try() catch{}

try() catch{}

try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(root, path))) {
  xxxxx  
}catch{
  xxxxx  
}

和平常見的不一樣

這種情況的()中的程式碼一般放的是對資源的申請,如果{}中的程式碼出項了異常,()中的資源就會被關閉

對檔案的操作比較常見。