FileOutputStream(Sting filename, boolean append)
第二个参数为 true 的时候为添加

解决方案 »

  1.   

    java.io.FileOutputStream
    java.io.FileWriter
    都有带 boolean append 参数的构造,可以实现续写
    FileOutputStream(File file, boolean append)
    FileOutputStream(String name, boolean append)
    FileWriter(File file, boolean append)
    FileWriter(String name, boolean append)给 append 为 true,之后直接写就行了。
      

  2.   

    中文会有乱码,怎么用BufferedOutputStream来处理啊
      

  3.   

    package studyproject;
    import java.io.*;
    public class writeFile
    {
      public writeFile()
      {
      }
      public static void main(String[] args)
          throws FileNotFoundException
      {
        String aa = "d:\\aaa.txt";
        File my = new File(aa);
        PrintWriter pw = null;
          FileOutputStream fos = new FileOutputStream(aa,true);//续写
          pw = new PrintWriter(fos);
          pw.println("\u6211\u662F\u4E2D\u56FD\u4EBA");
        pw.close();
        
      }}