try-with-resources
JDK1.7之後,引入了try-with-resources,可以簡化關閉資源代碼
以下代碼會自動關閉資源,不用 finally
try(FileInputStream fileInputStream = new FileInputStream("test.txt")) {
fileInputStream.read();
}catch (Exception e){
}
try-with-resources
JDK1.7之後,引入了try-with-resources,可以簡化關閉資源代碼
以下代碼會自動關閉資源,不用 finally
try(FileInputStream fileInputStream = new FileInputStream("test.txt")) {
fileInputStream.read();
}catch (Exception e){
}