- import java.io.*;
- class Demo3
- {
- public static void main(String[] args) //throws IOException
- { BufferedReader ber= null;
- BufferedWriter bfr = null;
-
- try
- { //这个地方没太明白?为什么不在外面也定义一下FileReader和FileWriter呢?
- //如果传的文件不存在呢?大侠指教一下 ,
- ber = new BufferedReader(new FileReader("demo1.java"));
- bfr = new BufferedWriter(new FileWriter("demo1_copy.java"));
- while(true)
- {
- String s = ber.readLine();
- if(s==null)
- break;
- else
- bfr.write(s);
- bfr.newLine();
- bfr.flush();
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException("数据异常");
- }
- finally
- {
- try
- {
- if(ber== null)
- ber.close();
- }
- catch (Exception e)
- {
- throw new RuntimeException("读出数据异常");
- }
- try
- {
- if(bfr== null)
- bfr.close();
- }
- catch (Exception e)
- {
- throw new RuntimeException("写入数据异常");
- }
-
- }
-
- }
- }
复制代码
谢谢 |
|