java 追加文件

 

FileWriter writer = null;

String fileName="d://my.txt";

String line="要追加的内容";
try {
    // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件 ,false 表示覆盖原内容
    writer = new FileWriter(fileName, true);
    writer.write(line);
} catch (IOException e) {
    e.printStackTrace(); 
} finally {
    try {
        if(writer != null){
            writer.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

  

posted @ 2015-06-03 15:31  荣超  阅读(165)  评论(0编辑  收藏  举报