• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to know whether a file is in use or not  RSS feed

 
venkateswara reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I want to know is there any method or procedure in Java to know whether a file is in use or not.if any body knows plz help me.
thanks in advance.
Regards
venkat
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to use FileChannel's tryLock() method for this. It's not 100% reliable, and it depends on the operating system. But if this method returns null, it indicates that some other process is working with the file. If it returns a FileLock object, then to the best of our knowledge, the file was not being accessed by another process, and the JVM now has exclusive access to the file. I'd recommend testing this on whatever OS you're using to see how well it works in practice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!