Java面试题:JDK不同版本处理IO流异常的标准代码
生活随笔
收集整理的這篇文章主要介紹了
Java面试题:JDK不同版本处理IO流异常的标准代码
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
QUESTION:JDK不同版本處理IO流異常的標準代碼?
answer:JDK1.6版本及以前:
FileInputStream fis=null;FileOutputStream fos=null;try{fis=new FileInputStream("C:\\Users\\ylh31\\Desktop\\應用軟件\\節(jié)奏 (Tempo)_EXO.mp3");fos=new FileOutputStream("E:\\test3.mp3");int b;while ((b=fis.read())!=-1){fos.write(b);}}finally { //try{}finally{}嵌套是能關一個盡量關一個try {if (fis!=null)fis.close();}finally {if (fos!=null)fos.close();}}JDK1.7版本
try(FileInputStream fis=new FileInputStream("C:\\Users\\ylh31\\Desktop\\應用軟件\\節(jié)奏 (Tempo)_EXO.mp3");FileOutputStream fos=new FileOutputStream("E:\\test3.mp3");) {int b;while ((b=fis.read())!=-1){fos.write(b);}}?
總結(jié)
以上是生活随笔為你收集整理的Java面试题:JDK不同版本处理IO流异常的标准代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cosine_similarity和to
- 下一篇: 文献阅读课12-Fine-Grained