Java input / output: how to add to an existing text file

Hi, I have no problem writing or adding to the file, the only problem is that as soon as I quit the program and then run it again, it will create a new file overwriting my original file. This is a problem as I use a text file to save the current table.

Is there a way to get an already created text file as an object and then add to it?

Thanks in advance.

+3
source share
3 answers

There is a constructor for FileWriter that allows you to set the add using a boolean. javadoc

+3

FileWriter ( ) FileOutputStream, (, FileWriter) append ( FileWriter) ( IMO).

FileWriter doc:

. , . , OutputStreamWriter FileOutputStream.

+6

java.io.FileWriter. append true .

+1
source

Source: https://habr.com/ru/post/1743376/


All Articles