Crunch Crunch - 1 year ago 135
Android Question

Delete file from internal storage

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 Source

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(ih.getImgPath(id));
boolean deleted = file.delete();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download