Possible to test if file is open in another process?

Discussion in 'Java' started by Chris, Nov 26, 2005.

  1. Chris

    Chris Guest

    Is it possible to test if a file is open by another process?

    I don't want to lock the file. I just want to know if another process has it
    open for any reason.

    I'm using JDK 1.4, so NIO is available. I couldn't find any methods that
    would do it, though. The closest ones I could find had to do with creating a
    FileLock on a channel. But that doesn't help.
     
    Chris, Nov 26, 2005
    #1
    1. Advertising

  2. Chris

    Marc E Guest

    maybe you could try renaming the file to itself. if the file is locked, it
    should return false
    "Chris" <anon> wrote in message
    news:4388d805$0$28514$...
    > Is it possible to test if a file is open by another process?
    >
    > I don't want to lock the file. I just want to know if another process has
    > it open for any reason.
    >
    > I'm using JDK 1.4, so NIO is available. I couldn't find any methods that
    > would do it, though. The closest ones I could find had to do with creating
    > a FileLock on a channel. But that doesn't help.
    >
     
    Marc E, Nov 26, 2005
    #2
    1. Advertising

  3. Chris

    Chris Smith Guest

    Marc E <> wrote:
    > maybe you could try renaming the file to itself. if the file is locked, it
    > should return false


    No, that would depend on the operating system. Without cooperative
    locking, there is no way to accomplish the requested task in a portable
    way.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Nov 26, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page