Alex Rivera | Logout

delete temporary file in java

Asked 2009-06-22T10:36:19.780
25

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

temp = File.createTempFile("temp", ".txt");
temp.deleteOnExit();
fileoutput = new FileWriter(temp);
buffout = new BufferedWriter(fileoutput);
Edit
Report

1 Answer

0

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!

answered 2009-06-22T10:47:10.273

Your Answer