Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for File Open or Closed state  RSS feed

 
Ron Yorrick
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am working on project that requires checking to see if a file is open or closed. The application takes the information in the file on one system and places it on another system to modify. I have tried setting up a file lock so that I can lock the file using the FileChannel and FileLock api's. I am in a windows environment. When I test the program with the file already open in notepad, the program is still able to get a lock on the file even though I expect it not to be able to. The only time it fails is if I run another java thread that attempts to get the lock for the same file. However, it does not seem to work if a another user has it "open" using some type of editor.
Is there anyway at all to check to see if the file is open or closed and gain exclusive access to that file? For example, a user is editing the file using Microsoft Word, and my java application needs exclusive access to that file needs to check if it is open period. For the purposes of this project, there is highly sensitive information that needs to be transferred, and it can not be being edited by an outside application while the application is moving the file. Any guidance would be appreciated.
 
Joseph Kampf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ron Yorrick:
When I test the program with the file already open in notepad, the program is still able to get a lock on the file even though I expect it not to be able to.

Note Pad does not lock the file. The same is true with Wordpad.

MS Word does however lock the file.

Joe
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!