本帖最后由 包晗 于 2012-7-28 22:44 编辑
- <P>import java.io.*;</P>
- <P>class CopyTest
- {
- public static void main(String[] agrs)throws IOException
- {
- copy_2();
- }
- public static void copy_2()
- {
- FileWriter fw= null;
- FileReader fr= null;
- try
- {
- fw = new FileWriter("systemDemo_copy1.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);
- }</P>
- <P>
- }
- 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)
- {
- }</P>
- <P> }
-
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
- </P>
复制代码 为啥 运行时报错了
但是又有 空的systemDemo_copy1.txt 出现
|
|