You can't use this to reliably lock the file.

You must use java.io.File.createNewFile to create the entry on disk, because in POSIX we must use open with the O_CREAT flag to ensure we are the only process which created this entry in the parent directory.  This is required to be compatible with C Git's locking protocol on POSIX platforms.