Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

FileLock: how to delete a locked file?

Thread view: 
yay_frogs@yahoo.com - 18 Jul 2006 22:43 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.