从内部存储中删除文件 [英] Delete file from internal storage

查看:28
本文介绍了从内部存储中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除存储在内部存储器中的图像.到目前为止,我已经想出了这个:

I'm trying to delete images stored in internal storage. I've come up with this so far:

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

这是来自另一个问题,回答:

And this is from another question, which was answered with:

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

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

My example always returns false. I can see the file fx 2930.jpg in DDMS in eclipse.

推荐答案

getFilesDir() 不知何故不起作用.使用返回整个路径和文件名的方法给出了所需的结果.代码如下:

The getFilesDir() somehow didn't work. Using a method, which returns the entire path and filename gave the desired result. Here is the code:

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

这篇关于从内部存储中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆