1

I'm trying to delete a file that I earlier created in my android app. The problem I'm having is that the file won't go away. Even though everything seems to work.

I've looked at several post here on stackoverflow, but still not solution. The garbage collections was one of the hints I've found.

System.gc();
System.out.println("Exists: "+file.exists());
System.out.println("Read: "+file.canRead());
System.out.println("Write: "+file.canWrite());
System.out.println("Deleting: " + file);
boolean r = file.delete();
System.out.println("Result of deletion: "+r);
System.gc();

And the result in the log

Exists: true
Read: true
Write: true
Deleting: data/data/no.ntnu.kpro.app/files/kprothales/XOMessage/8
Result of deletion: true

Does anyone have any idea as to why it isn't removed?

EDIT: Lucifer: Yeah, I have set WRITE_EXTERNAL_STORAGE permission in the manifest. ShineDown: No, it is just a file without an extension. For now it is containing xml, but this is going to change over time, hence why I have not called it .xml. Could this be a problem? chintan khetiya: I believe this line is allready included in the code above.

4

1 回答 1

1

在这里检查答案:

Android:如何删除内部图像文件

这基本上是建议调用deleteFile:

if(activity.deleteFile(imageName)) Log.i(TAG, "图片已删除。");

于 2013-08-19T21:00:26.473 回答