i am writing a string to a file in android using :
BufferedWriter writer = new BufferedWriter(new FileWriter(order));
writer.append(placedOrder);
whether i use
writer.write(placedOrder); // or
writer.append(placedOrder);
the data of the file is erased every time i run this code.
I want to add the data to the end of file.
Ex: When i run first time :
file output
My
Ex: When i run second time :
file output becomes
My
Name
Ex: When i run third time :
file output
My
Name
is
Ex: When i run fourth time :
file output
My
Name
is
Hisham.
and so on. Like having a record of all previous outputs.
Your current code uses FileWriter with default append mode set to false. You need to use the constructor in which you can set append to true: