Question

I have a file with this path:

file:/mnt/sdcard/Android/data/myapp/files/Pictures/IMG_20140108_160223.jpg

When I try this code:

File f = new File(path);
f.delete();

The file is not deleted. How can I do?

Was it helpful?

Solution

I've found a similar question here:

How to delete a file from SD card?

The file: prefix seems unnecessary.

try/mnt/sdcard/Android/data/myapp/files/Pictures/IMG_20140108_160223.jpg

Also you have to give permission if you are using >1.6 SDK

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

in AndroidManifest.xml file

OTHER TIPS

You may need to use

file.getCanonicalFile().delete();

or even (assumming this is a context)

this.deleteFile("string");

More Infos here to delete file with context object

You may also delete your file:/ at the beginning of your File object creation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top