How to delete a file/folder in a SDCARD under Android Platform? [closed]

 ̄綄美尐妖づ 提交于 2020-01-15 06:59:43

问题


I want to know how to delete a file/folder in SD Card. I tried the code below:

File folder = Environment.getExternalStorageDirectory();
String fileName = folder.getPath() + "/LOST.DIR/ppt52.ppt";
File myFile = new File(fileName);
if(myFile.exists()) {
    myFile.delete();
}

but it didn't work.


回答1:


Maybe the folder you are trying to access is Protected. So try to change the access mode before accessing it.

Or you are missing the following permission,

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


来源:https://stackoverflow.com/questions/8922714/how-to-delete-a-file-folder-in-a-sdcard-under-android-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!