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?
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?
This depends on your operating system:
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.
A file can appear in more than one place (with hard links) Deleting a file removes one of the hard links (possibly the only) If there is a link somewhere else, the file is still accessible.
Files which are deleted, but open continue to take up disk space and if large enough can mean your space used and the size of all the files you can find on your disk is different.
BTW: You can read/write the contents of an open file (deleted or not) if you look in /proc/{pid}/fd/{fid}
© 2022 - 2024 — McMap. All rights reserved.
rm
only disassociates the file from its path, and only when all handles to the file are gone will it actually be deleted (it can actually be recovered easily if it is still open). – Magalymagan