1

I am writing a file writer that writes an ID and name, both of String to a text file. This asks for user input then stored the data in a txt file. But when I run this again any new data overrides the previous, therefore the data never save to a txt file.

Could anyone tell me how I would save this data so that any new data added is stored on the next line and not override the previous?

Thanks

apapapaa
  • 27
  • 6

2 Answers2

1

Activate append mode to the FileWritterby addig trueas second paremeter:

FileWriter write = new FileWriter(newTextFile, true);

Check FileWriter usage

canillas
  • 414
  • 3
  • 13
0

You have to check if file with the same name exists already. If it does use that file. Because right now you create new file and overwrite old one every time.

fazic
  • 29
  • 1
  • 5