Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append to a text file in android?

Tags:

android

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

like image 751
Beginner Avatar asked Apr 15 '11 15:04

Beginner


People also ask

How do you append data to a file?

If you are working on text data and the number of write operations is less, use FileWriter and use its constructor with append flag value as true . If the number of write operations is huge, you should use the BufferedWriter. To append binary or raw stream data to an existing file, you should use FileOutputStream.

What is append in Android?

append(char c) Appends the specified character to this Appendable . abstract Appendable. append(CharSequence csq, int start, int end) Appends a subsequence of the specified character sequence to this Appendable .

Why we use append in Android?

Append(String) Convenience method to append the specified text to the TextView's display buffer, upgrading it to android.


1 Answers

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

like image 193
Umesh K Avatar answered Oct 05 '22 02:10

Umesh K