import java.io.*;
class test{
public static void main(String[] args){
//复制文件
FileReader fr = null;
FileWriter fw = null;
try{
fr = new FileReader("temp.txt");
fw = new FileWriter("test_copy.txt");
char[] arr = new char[1024];
int num;
while((num = fr.read(arr))!=-1){
System.out.println(num);
fw.write(arr,0,num);
}
}catch(IOException e){
throw new RuntimeException("文件复制失败");
}
finally{
try{
if(fr!=null){fr.close();}
}catch(IOException e){
throw new RuntimeException("读取流关闭失败");
}
try{
if(fw!=null){fw.close();}
}catch(IOException e){
throw new RuntimeException("写入流关闭失败");
}
}
}
}
Java——文件复制异常处理
最新推荐文章于 2021-11-01 22:48:51 发布