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?
josh.s17@gmail.com - 19 Jul 2006 03:23 GMT
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.
> I'm writing a method that needs to:
>
[quoted text clipped - 9 lines]
> release the lock and let some other process accidentally try to access
> the local file before my process deletes it. What can I do?
yay_frogs@yahoo.com - 19 Jul 2006 16:13 GMT
> 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.
Tim Smith - 20 Jul 2006 04:58 GMT
> 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).

Signature
--Tim Smith