Getting list of open files

I have two related questions. How can I get a list of all the files that are currently open on a particular machine? I'm using Windows, so I don't know of anything like Runtime.exec("lsof");

. More specifically, I need to see if a particular (given) file is currently open.

The second question that I have is how can I see if a particular file is open via a (signed) applet, with whatever security manager the browser has installed?

Thanks a lot.

--Jay

[510 byte] By [kempshalla] at [2007-10-2 1:45:26]
# 1
There is no way to do this in pure java.Given that, why do you feel you need to do this?
IanSchneidera at 2007-7-15 19:09:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Sysinternals probably has something that will do most or all of that.
ChuckBinga at 2007-7-15 19:09:33 > top of Java-index,Java Essentials,Java Programming...
# 3

> There is no way to do this in pure java.

>

> Given that, why do you feel you need to do this?

I have an applet that takes a group of files, compresses them together, and then uploads and downloads the compressed archive to/from a server and uncompresses them on the download end. Of course, if one the files that's supposed to be archived or unarchived is open, the applet won't work. I'm trying to write some code that, if one of these files is open, will notify the users that they have to close them.

kempshalla at 2007-7-15 19:09:33 > top of Java-index,Java Essentials,Java Programming...
# 4

> > There is no way to do this in pure java.

> >

> > Given that, why do you feel you need to do this?

>

> I have an applet that takes a group of files,

> compresses them together, and then uploads and

> downloads the compressed archive to/from a server and

> uncompresses them on the download end. Of course, if

> one the files that's supposed to be archived or

> unarchived is open, the applet won't work. I'm trying

> to write some code that, if one of these files is

> open, will notify the users that they have to close

> them.

Just attempt the operation of archiving/unarchiving, and deal gracefully with the possible exception, such as notifying the user of the failure at that point.

Even if you could determine if all the files weren't open, as soon as you determine that, the determination can be stale anyway as one or more of those files could subsequently be opened while you're trying to do the archive/unarchive operation, and you'd still have to deal with it.

warnerjaa at 2007-7-15 19:09:33 > top of Java-index,Java Essentials,Java Programming...
# 5

Open the file as a RandomAccessFile with "rw" access. This will fail if you can't get an exclusive lock on the file.

If you want to be really, really sure (for multi-platform handling), grab an exclusive FileLock using the RAF's underlying channel. That will definitely fail if the file is opened elsewhere.

- K

trumpetinca at 2007-7-15 19:09:33 > top of Java-index,Java Essentials,Java Programming...