hi,
I want to check if a file is open or not using Java. I want to know if
the file is accessed by some other program while i m opening it though
java program.
|
|
1
|
|
|
|
Reply
|
natikarsunil
|
2/26/2008 8:43:41 PM |
|
On Tue, 26 Feb 2008 12:43:41 -0800 (PST), natikarsunil@gmail.com wrote:
> I want to check if a file is open or not using Java. I want to know
> if the file is accessed by some other program while i m opening it
> though java program.
It's a strange thing to need to know. Are you just curious, or is
there a real problem you can't solve without knowing this information?
Anyway pure Java does provide any mechanisms to do that. This is
probably one of the more portable solutions but requires an external
helper that's available on Unix and Unix-like systems:
Runtime.getRuntime().exec("lsof " + filename);
On Windows there is Process Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
But whether you can use it from your java application is another
story.
You might look into solutions based on JNI.
/gordon
--
|
|
0
|
|
|
|
Reply
|
Gordon
|
2/27/2008 7:06:30 AM
|
|