Java writing to a deleted file

后端 未结 3 1968
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 08:16

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 no

3条回答
  •  孤街浪徒
    2021-01-04 08:43

    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.

提交回复
热议问题