1.try-catch-finally
2.try-with-resources
使用方法
try(//这里定义你要使用的资源){} catch(){}
注意:try()里只能存放流对象(资源对象),什么是资源呢?就是会自动实现AutoCloseable接口
使用2方法时会在资源使用完毕后自动对其释放close
- try-with-resources resources 方式 资源 withtry-with-resource resource方式 资源 try-with-resources resources方式 资源 try-with-resources try-with-resource try-with-resources resources java with try-with-resources妙招resources代码 try-with-resource resource java with try-with-resource语法resource java try-with-resources语句resources with try-with-resource语法resource with