Android Can';t从SD卡中删除文件
我正在使用这个代码Android Can';t从SD卡中删除文件,android,eclipse,Android,Eclipse,我正在使用这个代码 public void onClick(DialogInterface dialog, int which) { File dir = new File (Environment.getExternalStorageDirectory() + "/MyApp/MyFolder"); if (dir.isDirectory()) {
public void onClick(DialogInterface dialog, int which) {
File dir = new File (Environment.getExternalStorageDirectory() + "/MyApp/MyFolder");
if (dir.isDirectory())
{
File file = new File(card.imagePath);
file.delete();
}
但这并不是从卡片上删除文件。知道为什么吗?- 检查文件是否存在
- 如果您对文件具有写入权限,请检查文件权限
File file = new File(card.imagePath);
if(file.isExists()){
file.delete();
System.out.print("File exists and delete");
} else{
System.out.print("File NOT exists");
}
添加任务::
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
此外,请使用适当的
文件
构造函数而不是串联,并确保您具有写入外部存储
权限。