Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2008

Tip: Looking for answers? Try searching our database.

Check if a file is open or not

Thread view: 
natikarsunil@gmail.com - 26 Feb 2008 20:43 GMT
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.
Gordon Beaton - 27 Feb 2008 07:06 GMT
> 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

--


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.