java - 如何在不覆盖的情况下保存文本文件?

标签 java fileoutputstream

我想保存在文本文件中而不覆盖当前数据。我的意思是下一个将要保存的数据将在我保存时转到新的/下一行,这是我的问题,我不知道该怎么做。

有人可以帮我解决这个问题吗?

这是 save() 方法中的代码:

 public void save(String filename) throws IOException
{
    FileOutputStream fOut = new FileOutputStream(filename);
    ObjectOutputStream outSt = new ObjectOutputStream(fOut);
    outSt.writeObject(this);
}

最佳答案

阅读docs

public FileOutputStream(File file, boolean append) throws FileNotFoundException Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

关于java - 如何在不覆盖的情况下保存文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7563327/

相关文章:

android - FileOutputStream 因 FileNotFoundException 而失败,即使文件显然存在、可写且具有权限

java - 带有文本文件的不完整 Java 文件输出流

java - 无法使用 DOM4J 解析 XML

java - 如何在 maven Postman-plugin 中启用 STARTLS

java - 插入声音/音频

java - Google App Engine的自定义异常(exception)消息格式-Java

Java编写Shift-JIS CSV格式文件

java - 如何使用 Spring 4 注入(inject)键值映射?

java - 我可以使 FileInputStream.read 阻塞,直到同一文件上的 FileOutputStream 关​​闭吗?

Java FileOutputStream 设置文件图标