try() catch{}

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

和平常见的不一样

这种情况的()中的代码一般放的是对资源的申请,如果{}中的代码出项了异常,()中的资源就会被关闭

对文件的操作比较常见。

posted @ 2018-12-23 11:01  heroic_zjx  阅读(158)  评论(0编辑  收藏  举报