Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java writing to a deleted file

I'm using FileWriter to write to a file and noticed that even after I have deleted the file (out of process) the FileWriter does not throw any exception.

Is this normal?

like image 827
DD. Avatar asked Feb 06 '12 18:02

DD.


2 Answers

This depends on your operating system:

  • On Windows, you'd typically not be able to delete an open file.
  • On Unix, deleting an open file and continuing to write into it (or read from it) is perfectly acceptable. Once you delete the file, it will no longer have a directory entry. However, its contents will continue to exist on disk until the file is closed. Once all open handles that refer to the file get closed, the OS will automatically reclaim the disk space.
like image 110
NPE Avatar answered Sep 22 '22 11:09

NPE


Yes, it's normal. Using most of the conventional ways of doing I/O, if the file doesn't exist, it creates it for you. This of course pending that you deleted it before you began writing to it.

like image 36
OnResolve Avatar answered Sep 21 '22 11:09

OnResolve