How to know whether a file is open?

I want to get whether a file is open to be written by other program. How can i do that?
[94 byte] By [youhaodiyia] at [2007-11-27 7:37:13]
# 1
For what purpose?
ejpa at 2007-7-12 19:17:45 > top of Java-index,Core,Core APIs...
# 2
When my program read a file and at the same time another program is modifying this file, my program will get a incorrent content.
youhaodiyia at 2007-7-12 19:17:45 > top of Java-index,Core,Core APIs...
# 3
So write-lock the file.
ejpa at 2007-7-12 19:17:45 > top of Java-index,Core,Core APIs...
# 4
If I lock the file, other program will not read or change the file. I want to make my program to wait untill no other programs open the file.
youhaodiyia at 2007-7-12 19:17:45 > top of Java-index,Core,Core APIs...
# 5
Have the other program write lock the file; have this program wait for the lock; and then have it set a read-only lock if necessary.
ejpa at 2007-7-12 19:17:45 > top of Java-index,Core,Core APIs...