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();
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,之后直接写就行了。
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();
}}