Java try-with-resource语法
JDK1.7之前 在JDK1.7之前要确保外部资源关闭一般使用finally,如下 FileInputStream inputStream = null ; try { inputStream = new FileInputStream ( new File ( "user.csv" ) ) ; System . out . println ( inputStream . read ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e . getMessage ( ) , e ) ; } finally { if ( inputStream != null ) { try { inputStream . close ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e . getMessage ( ) , e ) ; } } } try-with-resource 在JDK1.7及之后对于实现了AutoCloseable接口的对象可以使用try-with-resource语法,该语法会确保外部资源的close方法被调用。如下: try ( FileInputStream inputStream = new