Nouvel Travay
Nouvel Travay

Reputation: 6472

what does it mean to delete a file on android

Naturally I thought to delete a file means to remove it from existence. So when I do

File file = new File(absPath);
....//add content
file.delete();

I expect that no further operation can be executed on file or it would throw an exception. But how come I can still add content to the file such as shown here Android saving Bitmap to SD card. So how do I delete a file so that it is completely gone? So that when someone go look through file manager, the file is no longer there? I am not in a position to test this now, so I was hoping for authoritative reference.

Upvotes: 0

Views: 42

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006839

how come I can still add content to the file such as shown here Android saving Bitmap to SD card.

That code creates a new file after deleting the old one.

So how do I delete a file so that it is completely gone? So that when someone go look through file manager, the file is no longer there?

Call delete() on a File object that points to the file. Then, do not use that same File object to write to the file again, thereby creating a new file, as the code that you link to does.

Upvotes: 2

Related Questions