How to write data with FileOutputStream without losing old data?

iSun picture iSun · Dec 17, 2011 · Viewed 112.4k times · Source

If you work with FileOutputStream methods, each time you write your file through this methods you've been lost your old data. Is it possible to write file without losing your old data via FileOutputStream?

Answer

Mat picture Mat · Dec 17, 2011

Use the constructor that takes a File and a boolean

FileOutputStream(File file, boolean append) 

and set the boolean to true. That way, the data you write will be appended to the end of the file, rather than overwriting what was already there.