android开发分享从内部存储中删除文件

我试图删除存储在内部存储器中的图像。 我已经拿出这个到目前为止:

File dir = getFilesDir(); File file = new File(dir, id+".jpg"); boolean deleted = file.delete(); 

这是从另一个问题,这是回答 :

 File dir = getFilesDir(); File file = new File(dir, "my_filename"); boolean deleted = file.delete(); 

我的例子总是返回false。 我可以在eclipse中看到DDMS中的文件fx 2930.jpg

    getFilesDir()以某种方式不起作用。 使用返回整个path和文件名的方法给出了所需的结果。 这里是代码:

     File file = new File(ih.getImgPath(id)); boolean deleted = file.delete(); 

    你有没有尝试过Context.deleteFile() ?

    这适用于我:

     File file = new File(photoPath); file.delete(); context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(photoPath)))); 

     String dir = getFilesDir().getAbsolutePath(); File f0 = new File(dir, "myFile"); boolean d0 = f0.delete(); Log.w("Delete Check", "File deleted: " + dir + "/myFile " + d0); 

    代码File dir = getFilesDir(); 不起作用,因为这是一个File对象的请求。 您试图检索声明目录path的string,因此您需要将“dir”声明为String,然后请求该目录的stringforms的绝对path由可访问该信息的构造函数返回。

    你也可以使用: file.getCanonicalFile().delete();

    你试过getFilesDir().getAbsolutePath()

    似乎通过使用完整path初始化File对象来解决您的问题。 我相信这也可以做到这一点。

      以上就是android开发分享从内部存储中删除文件相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/515304.html

      (0)
      上一篇 2020年11月30日
      下一篇 2020年11月30日

      精彩推荐