0

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?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
fran
  • 1,079
  • 1
  • 9
  • 25

2 Answers2

1

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.

Niklas
  • 20,301
  • 31
  • 118
  • 158
1

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

Community
  • 1
  • 1
Jay
  • 565
  • 5
  • 15