本帖最后由 位丹丹 于 2012-7-18 19:05 编辑
- import java.io.*;
- class CopyText
- {
- public static void main(String[] args) throws IOException
- {
- copy_2();
- }
- public static void copy_2()
- {
- FileWriter fw = null;
- FileReader fr = null;
- try
- {
- fw = new FileWriter("SystemDemo_copy.txt");
- fr = new FileReader("SystemDemo.java");
- char[] buf = new char[1024];
- int len = 0;
- while((len=fr.read(buf))!=-1)
- {
- fw.write(buf,0,len);
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("读写失败");
- }
- finally
- {
- if(fr!=null)
- try
- {
- fr.close();
- }
- catch (IOException e)
- { }
- if(fw!=null)
- try
- {
- fw.close();
- }
- catch (IOException e)
- { }
- }
- }
- }
复制代码 有点不明白,finally中处理的两个异常在catch代码块中怎么没有处理语句,只是try,并没有相应的处理操作,为什么在运行的时候没有出现异常?
|