如何删除存在的文件

Beg*_*ner 4 android

可能重复:
如何从SD卡中删除文件?

这应该对大多数人来说很简单,我想知道如何删除SD卡中的文件(/sdcard/folder)如果存在,即?

Taw*_*ani 27

试试这个:

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

File myFile = new File(fileName);
if(myFile.exists())
    myFile.delete();
Run Code Online (Sandbox Code Playgroud)


Mar*_*k B 1

这是通过java.io.File类来完成的。看看exists()delete()方法。

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