开发者

How to delete a file that exists [duplicate]

开发者 https://www.devze.com 2023-02-10 00:44 出处:网络
This question already has answers here: Closed 11 years ago. Possi开发者_如何转开发ble Duplicate:
This question already has answers here: Closed 11 years ago.

Possi开发者_如何转开发ble 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?


Try this:

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

File myFile = new File(fileName);
if(myFile.exists())
    myFile.delete();


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

0

精彩评论

暂无评论...
验证码 换一张
取 消