本帖最后由 陌路行者 于 2013-7-8 12:36 编辑
- import java.io.*;
- class CopyText
- {
- public static void main(String[] args)
- {
- FileReader fr = null;
- FileWriter fw = null;
- try
- {
- fr = new FileReader("RuntimeDemo.java");
- fw = new FileWriter("Runtime_copy.txt");
- char[] buf = new char[1024];
- int num = 0;
- while((num=fr.read(buf))!=-1)
- {
- //fr.read(buf);
- fw.write(buf,0,num);
- fw.flush();
- }
- }
- catch (IOException e)
- {
- }
- finally
- {
- try
- {
- fr.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- fw.close();
- }
- catch (IOException e)
- {
- }
-
- }
-
- }
- }
复制代码 为什么会报空指针异常
|
|