I am working on a portable java app that generates some files on the fly on the user's PC (windows xp). Now, what I want is to delete those temp files after the java program's exit. Obviously, java's file deletion mechanism can not be trusted. Even if I mark a file as to be deleted on exit (file.deleteOnExit() ) , most of the time开发者_StackOverflows it is not deleted. I use a wrapper (java2exe) to run it as an executable. Any suggestions or solutions are welcome ?
Thanks, Deep
I suspect that the reason that deleteOnExit
is failing is because your application still has the files open when your application exits. This will cause the delete to fail on Windows due to lingering file locks.
The solution is to close all streams for your temporary files before you exit.
精彩评论