Can File.exists and File.delete have a race condition?
Let's say thread-1 deletes a file and thread-2 checks for the existence of the same file. Now do I need to ensure that this does not happen simultaneously or does Java/OS take care of this by itself.
It depends on the file system, but assume there is no synchronization. If one thread or process* deleted the file mere nanoseconds after File.exists() has returned true the file no longer exists even though your program thinks it does. This isn't something you can do much about I fear.
* After all, the file can also be deleted from Explorer, or another program.