我想编写一个程序,保留以前在文件中编写的内容,并不断添加到文件中,而不是每次运行该程序时都擦除它。
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.Math;
class Movie_Ratings_2 {
public static void main(String[] args) {
Scanner n = new Scanner (System.in);
String fileName = "output.txt";
String x = n.nextLine();
try {
PrintWriter outputStream = new PrintWriter(fileName);
outputStream.println(x);
outputStream.close();
outputStream.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}