• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check file is in use.

 
Alka S.
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to check that file is in use or not without deleting the file . If it is in use I have display message file is in use.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will be a hard work - if not impossible at all.

Can you define, what you mean with 'in use'?

When I open a small file in an editor, the editor may close the file after reading.
When I save it to disk, the file can be reopened again - or a new file is written with the old name, while deleting the old file.

From an user/ application-view, the file is open all the time.
From a file-system view, it is only opened for two short times.
---
On Linux there is a system command 'lsof' - list open files.
I don't know if there is something similar on other platforms.
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get a file lock or check if a file is locked by other processes with java.nio.channels.FileLock. Of course, that assumes that the other processes are being nice and acquiring file locks when they are using files.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!