Implementing the Downloader (2)
(Part 1)
I had problems with moving files after their downloading has been finished. These problems did not occur on Unix-like operating systems like my OS X and Linux but only with Windows. I just was not able to move the file with file.renameTo of the Java API.
After some researching on the web and especially the Sun forums I saw that I am not alone with this problem. The solution is stupid but logical: Before using file.delete() or file.renameTo():
- Of course, make sure to close the file
- Call System.gc() and then System.runFinalization(). Sleep a second and run System.gc() again. This makes sure that the Sun Java VM really closes the file and frees resources associated with it.
- For temporary files, also use file.deleteOnExit()
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)