Malfunction Malfunction - 1 year ago 99
Android Question

android deleting a file from internal storage

I have created a file stored on internal storage from an activity. How can I delete this file from another activity?

I'm thinking I'll have to get the file's directory (which I'm not sure how to) and delete it. I tried using


but it won't work because I'm trying to call it from a non-static method.

Any help is appreciated.

Answer Source

Here is your answer :

File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download