delete temporary file in java

前端 未结 4 1477
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 23:26

I\'m creating temporary file in java but i\'m unable to delete it. This is the code I have written:

temp = File.createTempFile(\"temp\", \".txt\");
temp.dele         


        
4条回答
  •  清歌不尽
    2021-01-03 23:47

    You have to shut down a VM cleanly in order for the deleteOnExit to work properly (I suspect). On UNIX a kill would be a clean shutdown (i.e. the ShutdownHooks would be processed) whereas a kill -9 would be more like a force quit.

    deleteOnExit definitely works for me!

提交回复
热议问题