Markus "guruz" Goetz

[ index | hardware | projects and coding | p300 | blog | contact ]


p300 filesharing banner


November 18, 2007 at 2:52 pm.
Abgelegt unter: Coding, p300
guruz @ 2:52 pm

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()
Do you want to be notified when something new about p300 is blogged? Then subscribe via E-Mail or via RSS


Implementing the Downloader
Revision 541 released
p300 Revision 619 released

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus