Home » Android » How to append to a text file in android?

How to append to a text file in android?

Posted by: admin May 14, 2020 Leave a comment

Questions:
FileWriter f;
try {
 f = new FileWriter(Environment.getExternalStorageDirectory()+
                 "/Text/o1"+".txt");
     f.write("Hello World");
 f.flush();
 f.close();
}

I can create a file and write to it using the above code. How do i append to the text file without over writing it? thanks

How to&Answers:

Use FileWriter(File file,boolean append) constructor while creating FileWriter.