Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > FileLock: how to delete a locked file?

Reply
Thread Tools

FileLock: how to delete a locked file?

 
 
yay_frogs@yahoo.com
Guest
Posts: n/a
 
      07-18-2006
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?

 
Reply With Quote
 
 
 
 
josh.s17@gmail.com
Guest
Posts: n/a
 
      07-19-2006
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.

http://www.velocityreviews.com/forums/(E-Mail Removed) 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?


 
Reply With Quote
 
 
 
 
yay_frogs@yahoo.com
Guest
Posts: n/a
 
      07-19-2006

(E-Mail Removed) 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.

 
Reply With Quote
 
Tim Smith
Guest
Posts: n/a
 
      07-20-2006
In article <(E-Mail Removed) .com>,
(E-Mail Removed) 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
 
Reply With Quote
 
toddwh50 toddwh50 is offline
Junior Member
Join Date: Mar 2010
Posts: 1
 
      03-11-2010
Did you ever figure out how to do this? I have exactly the same dilemma.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to delete a locked file ? Ganesh C++ 7 05-08-2007 03:29 PM
To delete or not to delete? Lethal Computer Support 15 07-24-2005 11:47 PM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM
Cannot Delete, (The Delete Key Won't Work) Lee Something Computer Support 13 10-15-2003 09:51 PM



Advertisments