papski
papski

Reputation: 1281

How to save text file without overwriting?

I want to save in a text file without overwriting the current data. I mean the next data that will be save will go to the new/next line whenever I save and that is my problem, I don't know how to do that.

Could someone help me about this matter?

Here's the code in save() method :

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

Upvotes: 1

Views: 1201

Answers (1)

leonbloy
leonbloy

Reputation: 76026

Read the 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.

Upvotes: 3

Related Questions