FileLock: how to delete a locked file?

Discussion in 'Java' started by yay_frogs@yahoo.com, Jul 18, 2006.

  1. Guest

    I'm writing a method that needs to:

    1. Open a local file as a FileInputStream.
    2. Lock the local file.
    3. Upload the local file to a remote location.
    4. Delete the local file.
    5. Release the lock.

    Now it seems it is impossible to do this with the existing java.nio.*
    FileChannel and FileLock classes. There is no way to delete a locked
    file. Once the locked file is uploaded to the server, I can't afford to
    release the lock and let some other process accidentally try to access
    the local file before my process deletes it. What can I do?
    , Jul 18, 2006
    #1
    1. Advertising

  2. Guest

    Why not have a seperate lock file to the file you are uploading. Then
    you can delete the uploaded file and then release your lock.

    wrote:
    > I'm writing a method that needs to:
    >
    > 1. Open a local file as a FileInputStream.
    > 2. Lock the local file.
    > 3. Upload the local file to a remote location.
    > 4. Delete the local file.
    > 5. Release the lock.
    >
    > Now it seems it is impossible to do this with the existing java.nio.*
    > FileChannel and FileLock classes. There is no way to delete a locked
    > file. Once the locked file is uploaded to the server, I can't afford to
    > release the lock and let some other process accidentally try to access
    > the local file before my process deletes it. What can I do?
    , Jul 19, 2006
    #2
    1. Advertising

  3. Guest

    wrote:
    > Why not have a seperate lock file to the file you are uploading. Then
    > you can delete the uploaded file and then release your lock.


    Other programs won't care about my lock file or honor it.
    , Jul 19, 2006
    #3
  4. Tim Smith Guest

    In article <>,
    wrote:
    > Now it seems it is impossible to do this with the existing java.nio.*
    > FileChannel and FileLock classes. There is no way to delete a locked file.
    > Once the locked file is uploaded to the server, I can't afford to release
    > the lock and let some other process accidentally try to access the local
    > file before my process deletes it. What can I do?


    Well, if you are willing to give up some portability, you could always step
    outside of Java to delete the file. For example, if you are on a Unix
    system, you could spawn a processes to do "rm yourfile". That should work,
    as Unix allows deleting opened files, and a lock should have no effect on
    that (as deleting isn't an operation on the file--it is just removing a
    directory link to the file).

    --
    --Tim Smith
    Tim Smith, Jul 20, 2006
    #4
  5. toddwh50

    Joined:
    Mar 11, 2010
    Messages:
    1
    Did you ever figure out how to do this? I have exactly the same dilemma.
    toddwh50, Mar 11, 2010
    #5
    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.
Similar Threads
  1. David Zimmerman

    confused abt FileLock behavior

    David Zimmerman, Jul 28, 2003, in forum: Java
    Replies:
    3
    Views:
    433
  2. Replies:
    0
    Views:
    5,173
  3. alejandrina

    Problem with FileLock

    alejandrina, Jul 13, 2007, in forum: Java
    Replies:
    12
    Views:
    619
    alejandrina
    Jul 30, 2007
  4. Harold Yarmouth

    Apparent bug in FileLock

    Harold Yarmouth, Nov 19, 2008, in forum: Java
    Replies:
    1
    Views:
    321
    Harold Yarmouth
    Nov 20, 2008
  5. Josef 'Jupp' SCHUGT

    epoch/2 bug in filelock.rb?

    Josef 'Jupp' SCHUGT, Jan 11, 2004, in forum: Ruby
    Replies:
    1
    Views:
    112
    Josef 'Jupp' SCHUGT
    Jan 14, 2004
Loading...

Share This Page