- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- public class charStream {public static void main(String[] args) throws IOException {
- //创建字符流缓冲读取、写入对象和文件目录
- BufferedReader br = new BufferedReader(new FileReader("a.txt"));
- BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt"));
- // 定义一个字符串用于存储读取的数据
- String str = null;
- // 遍历文件的字符,readLine一行一行读取。
- while((str = br.readLine())!=null){
- //把读取的数据写入b.txt
- bw.write(str);
- }
- // 关闭流
- br.close();
- bw.close();
- }
- }
复制代码 |