QUESTION:JDK不同版本处理IO流异常的标准代码?
answer:JDK1.6版本及以前:
FileInputStream fis=null;FileOutputStream fos=null;try{fis=new FileInputStream("C:\\Users\\ylh31\\Desktop\\应用软件\\节奏 (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\\应用软件\\节奏 (Tempo)_EXO.mp3");FileOutputStream fos=new FileOutputStream("E:\\test3.mp3");) {int b;while ((b=fis.read())!=-1){fos.write(b);}}