首页 > 代码库 > 字符缓冲流 Day20

字符缓冲流 Day20

package com.sxt.prac;
/*
 * 缓冲流之字符缓冲流   defaultCharBufferSize = 8192;
 * 1.读入到程序
 * 2.程序写到文件
 * 3.采用循环边读边写
 * 两个独有的方法:
 * BufferedReader  br.readLine();//读内容 没有返回null
 * BufferedWriter  bw.newLine;
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TestBuffered {
    public static void main(String[] args) throws IOException {
        //读入
        BufferedReader br = new BufferedReader(new FileReader(new File("G:\\testBufferedSource.txt")));
        //写出
        BufferedWriter bw= new BufferedWriter(new FileWriter(new File("G:\\testBuffered.txt")));
        String line = null;
        //循环边读边写
        while((line = br.readLine()) != null){//
            bw.write(line);
            bw.newLine();//
        }
        br.close();
        bw.close();
        System.out.println("----------end");
    }
}

 

字符缓冲流 Day20