1 package a.ab;
2
3 import java.io.*;
4
5 public class FileReadWrite {
6 public static void main(String[] args) {
7 FileWriter fw=null;
8 BufferedWriter bw=null;
9 try{
10 //将f1文件的内容复制到f2文件中
11 File f1=new File("D:\\DD\\d.txt");
12 fw=new FileWriter(f1);
13 bw=new BufferedWriter(fw);//带缓冲区的字符输出流
14 for(int i=0;i<3;i++){
15 bw.write("abcd"+i);
16 bw.newLine();
17 bw.flush();
18 }
19 }catch(Exception ex){
20 ex.printStackTrace();
21 }finally{
22 try {
23 fw.close();//关闭文件写操作
24 } catch (IOException e) {
25 e.printStackTrace();
26 }
27 try {
28 bw.close();
29 } catch (IOException e) {
30 e.printStackTrace();
31 }
32 }
33 }
34 }