InputStream is = null;
OutputStream os = null; try {} catch (IOException e) {
}finally{
try {
if(os!=null){
os.close();
}
if(is!=null){
is.close(); } } catch (IOException e2) {}
}
而现在你可以这样写:
try(
InputStream is = new FileInputStream("..."); OutputStream os = new FileOutputStream("..."); ){ }catch (IOException e) { } try()里每个声明的变量类型都必须是Closeable的子类