开发者

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

开发者 https://www.devze.com 2023-01-31 09:40 出处:网络
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\

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

精彩评论

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