try-with-resources使用示例
1 try (InputStream is = new FileInputStream("test")) { 2 is.read(); 3 ... 4 } catch(Exception e) { 5 ... 6 } finally { 7 //no need to add code to close InputStream, its close method will be internally called 8 //(无需添加关闭InputStream输入流的代码,其close()方法会自行调用) 9 }
转自:https://blog.csdn.net/frgod/article/details/53414813