I was creating an application in Java for which I want only one instance running. For this purpose I created a file and got a lock while my application is running.
I used same sample as you and got same problem on Mac OS X. It seems that file lock does not prevent file deletion on POSIX systems . Your app wil still have some kind of handle to that file until you unlock it. So consider using lock file with PID in it's name( or inside file).