文件字符流

package com.study02;

import java.io.FileWriter;
import java.io.IOException;

public class fileWrite {
public static void main(String[] args) {
//创建对象
FileWriter writer= null;
try {
writer = new FileWriter("ccc.txt");


//写数据
writer.write("hello");//写到了缓冲区

//手动刷新缓冲
writer.flush();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//关闭,添加了手动刷新缓冲可不写close
if (writer!=null) {
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

}
}

posted @ 2019-11-10 15:14  Princess1  阅读(106)  评论(0编辑  收藏  举报