演示BufferedWriter的使用,也是关闭外层流即可

 

package com.io.writer;

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 * 演示BufferedWriter的使用,也是关闭外层流即可
 */
public class BufferedWriter_ {
    public static void main(String[] args)throws Exception {
        String filePath="d:\\ok.txt";
        //创建BufferedWriter  filePath后加了true,表示以追加的方式写入而不是覆盖了

        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath,true));
        bufferedWriter.write("hello!沐晴");
        //插入一个换行符
        bufferedWriter.newLine();
        bufferedWriter.write("hello2!沐晴");
        bufferedWriter.newLine();
        bufferedWriter.write("hello3!沐晴");

        bufferedWriter.close();

    }
}

 

posted @ 2022-04-30 12:35  胖虎9  阅读(101)  评论(0编辑  收藏  举报