Delete file from internal storage

Crunch picture Crunch · Mar 30, 2011 · Viewed 154.2k times · Source

I'm trying to delete images stored in internal storage. I've come up with this so far:

File dir = getFilesDir();
File file = new File(dir, id+".jpg");
boolean deleted = file.delete();

And this is from another question, which was answered with:

File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();

My example always returns false. I can see the file fx 2930.jpg in DDMS in eclipse.

Answer

Crunch picture Crunch · Mar 30, 2011

The getFilesDir() somehow didn't work. Using a method, which returns the entire path and filename gave the desired result. Here is the code:

File file = new File(inputHandle.getImgPath(id));
boolean deleted = file.delete();