IO流7 --- FileWriter写出数据的操作 --- 技术搬运工(尚硅谷)

  • FileWriter字符输出
@Test
public void test3(){
    File file = new File("hello1.txt");
    FileWriter fw = null;
    try {
        //自动创建文件。默认false,覆盖写;true追加写
        fw = new FileWriter(file, true);
        fw.write("天南地北");
    } catch (IOException e) {
        e.printStackTrace();
    }finally {
        if (fw != null){
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

  

posted @ 2019-10-18 16:55  地中有山  阅读(172)  评论(0编辑  收藏  举报