BufferedOutputStream bos = null;
try{
bos = new BufferedOutputStream(new FileOutputStream("d:/123.txt"));
}catch (Exception e){
System.out.println(e.getMessage());
} finally {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedOutputStream bos = null;
try{
bos = new BufferedOutputStream(new FileOutputStream("d:/123.txt"));
}catch (Exception e){
System.out.println(e.getMessage());
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
效果没区别,但是如果第一个在catch抛了异常,第二种写法不会关闭流