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
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.
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 .
Append(String) Convenience method to append the specified text to the TextView's display buffer, upgrading it to android.
Use FileWriter(File file,boolean append)
constructor while creating FileWriter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With