Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将 java 控制台的内容保存到一个文本文件中,但是每次我关闭程序时,文本文件都会变为空白并重写它。即如果我今天写一个文件,关闭程序,明天再回来运行它,它已经记住了写入它的信息。
您要打开附加模式OutputStream。演示代码:
OutputStream
PrintWriter out = new PrintWriter( new FileOutputStream(new File(filename), true));
当您将流写入文件时,您所经历的是正常行为,这并不特定于 Java API。