public class FileWriterTest {
    public static void main(String[] args) {
        Writer fw=null;
        try{
            //创建FileWriter对象
            fw =new FileWriter("D:\\DOC\\mysaying.txt");
            //向文件写数据
            fw.write("预测未来最好的方式就是创造未来!");
            //fw.flush();
            System.out.println("文件写入成功");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件不存在");
        }finally {
            if (fw!=null){
                try{
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}