JDK1.7的关闭资源的方式
流的父类 都实现一个接口 AutoCloseable
可能自动关闭的接口 1.7新特性
FileIntpustream fis = null;
FileOutputStream fos = null;
try(
//要自动关闭的流
//前提是该类必须实现了AutoCloseable接口
//该处理异常 正常处理 和 原来一样
/系统会帮你 自动关闭流
FileIntpustream fis = new FileIntputSteam(“”);
FileOutputStream fos = new FileOutputSteam(“”);
){
int len = 0;
byte[] b = new byte[1024];
while((len=fis.read(b))!=-1){
fos.write(b,0,len);
}catch(IOException){
}
}