package com.io.ioDemo;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
//字符流写入文件
public class FileWriterDemo {
public static void main(String[] args) {
//创建一个字符流对象
FileWriter fw = null;
try {
fw = new FileWriter(new File("c:\\a.txt"));
//写入数据
fw.write("字符流写入文件");
fw.write("也可以用StringBuilder和StringBuffer追加写入");
//刷新流
fw.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
//关闭流
if(fw!=null){
try {
fw.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}