您为什么不使用以下代码对此进行测试:
File fdelete = new File(uri.getPath());if (fdelete.exists()) { if (fdelete.delete()) { System.out.println("file Deleted :" + uri.getPath()); } else { System.out.println("file not Deleted :" + uri.getPath()); }}我认为问题的一部分是您永远不要尝试删除文件,而只是创建一个具有方法调用的变量。
因此,在您的情况下,您可以尝试:
File file = new File(uri.getPath());file.delete();if(file.exists()){ file.getCanonicalFile().delete(); if(file.exists()){getApplicationContext().deleteFile(file.getName()); }}但是我认为这有点过分。
您添加了一条注释,说明您正在使用外部目录而不是uri。因此,您应该添加以下内容:
String root = Environment.getExternalStorageDirectory().toString();File file = new File(root + "/images/media/2918");
然后尝试删除该文件。



