Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t从SD卡中删除文件_Android_Eclipse - Fatal编程技术网

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" />

此外,请使用适当的
文件
构造函数而不是串联,并确保您具有
写入外部存储
权限。