0

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.

Community
  • 1
  • 1
Nouvel Travay
  • 6,292
  • 13
  • 40
  • 65

1 Answers1

2

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491