- 基本写法
finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } }
- IOUtils.closeQuietly
finally { // 2.6版本的时候,它过时了 IOUtils.closeQuietly(out); }
- try-with-resource
try ( ByteArrayOutputStream out = new ByteArrayOutputStream(); ) { // Do something } finally { }