Try:
class java.nio.channels.FileChannel methods tryLock, lock
This is the access to the locking operating system capabilities (like the flock system call in Unix) . It is different from checking "access denied" errors when the file is an executable one and is being executed in Windows, for instance.