1

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); } 

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Yep, a native solution is the best solution.
@Atticus: Why do you suggest a native solution? And how is leonbloy's good suggestion (1+ to him) a native solution?
@HovercraftFullOfEels Because instead of making a work around, he is telling the OP that you can just include a boolean flag to append the new content rather than overwriting it... And since this is supported natively by the language, i called it a "native solution"
Hm, I consider native solutions, those that require native code, often written in C or C++ and often requiring JNI (Java Native Interface), or JNA (Java Native Access).
@HovercraftFullOfEels are you trolling my use of the word native in this scenario? lol :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.