Hi I am having no problem writing to or appending to a file, the only problem is that as soon as I quit the program and then run it again, it creates a new file overwriting
There is a constructor for FileWriter which allows you to set appending with a boolean. javadoc
Usually, better than FileWriter (already suggested) is to use FileOutputStream, which also (like FileWriter
) has an append
parameter in one of its constructors, and which (unlike FileWriter
), does not silently assume the default charset encoding (slightly bad practice IMO).
From the FileWriter doc:
Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
Take a look at java.io.FileWriter. Setting append
to true should do the trick.