【发布时间】:2018-02-08 02:12:31
【问题描述】:
在以下块中:
try (final InputStream fis = new BufferedInputStream(Files.newInputStream(f.toPath()));
final ArchiveInputStream ais = factory.createArchiveInputStream(fn, fis)) {
System.out.println("Created " + ais.toString());
ArchiveEntry ae;
while ((ae = ais.getNextEntry()) != null) {
System.out.println(ae.getName());
}
}
这是否等同于以下块:
try {
final InputStream fis = new BufferedInputStream(Files.newInputS...;
} catch {
System.out.println("Created " + ais.toString());...
}
我在 apache common 的库中偶然发现了 try/catch 的这种语法,但我不确定如何使用它。如果我在这里能想到的唯一假设不正确,任何人都可以帮助我理解它或将我指向解释此语法的参考吗?我在这里用谷歌搜索和搜索了很多,但找不到任何适用的东西,尽管我的 search-fu 不是最好的。
提前致谢!
【问题讨论】:
-
不,我建议你了解
try-with-resources的作用 -
谢谢你,乔纳 B.
标签: java syntax coding-style try-catch