代码如下:
- public static void main(String[] args)
- {//定义缓冲读入流bufr
- BufferedReader bufr = new BufferedReader(new FileReader("a.txt"));
- //定义缓冲输出流 bufw
- BufferedWriter bufw = new BufferedWriter(new FileWriter("b.txt"));
- //定义变量line用于单行读取
- String line = null;
- while((line=bufr.readLine())!=null) //读入一行数据
- {//写入一行数据
- bufw.write(line);
- //换行
- bufw.newLine();
- //从缓冲区刷出数据入磁盘
- bufw.flush();
- }
- //关闭输入输出流
- bufw.close();
- bufr.close();
- }
复制代码 |
|