本帖最后由 CHJ 于 2013-9-29 22:24 编辑
- import java.io.*;
- class CopyTestByBuf
- {
- public static void main(String[] args)
- {
- BufferedReader bufr = null;
- BufferedWriter bufw = null;
- try
- {
- new BufferedReader(new FileReader("CopyTest.java"));
- new BufferedWriter(new FileWriter("CopyTest_1.txt"));
- String s = null;
- while ((s=bufr.readLine())!=null)
- {
- bufw.write(s);
- bufw.newLine();
- bufw.flush();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("读写失败!");
- }
- finally
- {
- try
- {
- if (bufr!=null)
- {
- bufr.close();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("读失败!");
- }
- try
- {
- if (bufw!=null)
- {
- bufw.close();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("写失败!");
- }
- }
- }
- }
复制代码 编译通过了,运行就出现这个异常Exception in thread "main" java.lang.NullPointerException
at CopyTestByBuf.main(CopyTestByBuf.java:15)
|