开发者

how to delete temp files (clean up) generated by a java program?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜