使用try-with-resource自動關流
```java
try(BufferedInputStream bis=new BufferedInputStream(new FileInputStream("D:/img/a.jpg"));
BufferedOutputStream bos= new BufferedOutputStream(new FileOutputStream("D:/img/b.jpg")))
{
int b=-1;
while((b=bis.read())!=-1){
bos.write(b);
}
bos.flush();
}catch(IOException io){
log.info("文件讀取寫出異常 ",e)
}
再也不用自己手動在finally塊關流了。有時候忘記關,流水線都跑不起來。
這樣的代碼簡潔而美觀。可讀性強。