8

Possible Duplicate:
How to delete a file from SD card?

This should be simple for most people, I want to know how to delete a file in the SD card (/sdcard/folder) if it exists i.e?

Community
  • 1
  • 1
Beginner
  • 28,539
  • 63
  • 155
  • 235

2 Answers2

42

Try this:

File folder = Environment.getExternalStorageDirectory();
string fileName = folder.getPath() + "/folder/image1.jpg";

File myFile = new File(fileName);
if(myFile.exists())
    myFile.delete();
Tawani
  • 11,067
  • 20
  • 82
  • 106
1

This is accomplished via the java.io.File class. Have a look at the exists() and delete() methods.

http://download.oracle.com/javase/1.5.0/docs/api/java/io/File.html

Mark B
  • 183,023
  • 24
  • 297
  • 295