我找到了一个很好的替代品
try-with-resources。它使用带有注释处理的Lombok库:
@Cleanup InputStream in = new FileInputStream(args[0]); @Cleanup OutputStream out = new FileOutputStream(args[1]); byte[] b = new byte[10000]; while (true) { int r = in.read(b); if (r == -1) break; out.write(b, 0, r); }但是,它不能正确处理异常。该错误已有1年以上的历史,并且仍未关闭:https
:
//pre.google.com/p/projectlombok/issues/detail?id=384



