Here is the code for writing a string to a text file.
try {
OutputStreamWriter out=new OutputStreamWriter(openFileOutput("counts.txt", MODE_APPEND));
try {
s = main_text.getText().toString();
out.write(s);
}
catch (java.io.IOException e) {
}
Now how to delete all the contents of a text file without deleting the file itself.
Actually when ever adding the next string to a file it appends next to the previous string. What is required is to over write the previous string.