Deleting files created with FileOutputStream

user396933 picture user396933 · Jul 20, 2010 · Viewed 26.7k times · Source

I'm developing for the Android platform.
My app creates a temp file with a simple call to:

FileOutputStream fos = openFileOutput("MY_TEMP.TXT", Mode);

It works fine because I can write to it and read it normally.

The problem is that when I exit from the app I want to delete this file. I used:

File f = new File(System.getProperty("user.dir"), "MY_TEMP.TXT");
f.delete()

But it always returns false and the file is not deleted.
I have tried:

File f = new File("MY_TEMP.TXT");
f.delete();

And it does not work either.

Answer

Palomo picture Palomo · Jul 21, 2010

I checked on this posting and the best way to delete a file created from FileOutputStream is a simple call from the Context method deleteFile(TEMP_FILE) as simple as that.