欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java 文件续写

程序员文章站 2022-03-10 19:52:44
public class FileWriterDemo { public static void main(String[] args) { FileWriter fw = null; try { // 传递true,代表不覆盖已有文件,追加 fw = new FileWriter("demo.tx ......
public class filewriterdemo {
    public static void main(string[] args) {
        filewriter fw = null;
        try {
            // 传递true,代表不覆盖已有文件,追加
            fw = new filewriter("demo.txt", true);
            fw.write("abcde\n");
        } catch (ioexception e) {
            system.out.println(e.tostring());
        } finally {
            try {
                if (fw != null)
                    fw.close();
            } catch (ioexception e) {
                e.printstacktrace();
            }
        }
    }
}