删除内部存储文件文件

2023-09-06 01:31:09 作者:黑色曼陀罗

我想删除存储在内部存储的图像。我想出了这个至今:

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();

这是另外一个问题,这是与回答:

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

我的例子总是返回false。我可以看到日食 FX 2930.jpg DDMS中的文件。

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

推荐答案

getFilesDir()不知何故没有工作。 使用方法,该方法返回整个路径和文件名,得到所希望的结果。这里是code:

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(ih.getImgPath(id));
boolean deleted = file.delete();