public void demo() throws FileNotFoundException, IOException { // 抛出异常
FileInputStream fis = null; // 赋初值
FileOutputStream fos = null;
try {
fis = new FileInputStream("a.txt");
fos = new FileOutputStream("b.txt");
byte[] arr = new byte[1024*8]; // 8192Bytes是有讲究的
int len;
while((len = fis.read(arr)) != -1) {
fos.write(arr,0,len);
}
}finally {
try{ // try...finally...嵌套是为了防止关闭流时出现异常
if(fis != null)
fis.close();
}finally {
if(fos != null)
fos.close();
}
}
}
jdk1.6及之前版本IO流异常处理标准代码
最新推荐文章于 2021-08-26 10:42:44 发布