Download to Excel then delete the temp file
843785Dec 31 2008 — edited Dec 31 2008I have succeeded in downloading data from my java application to an excel spreadsheet with multiple pages. That works fine. In doing this I write to a file. I now want to delete that file. I can get it to delete, but it happens before the user gets to download anything....or it does not delete.
Here is the code I tried.
//These are the variables I am using
long sec = System.currentTimeMillis(); // set the time stamp
String output="output."+sec+".xls"; // set the name of file
//This is the section of code that I'm having trouble with. If I comment out the last line it does not delete the file. If I leave the last line in, it deletes before I can download and save anything.
File newOutput = new File ("C:\\file_output\\", output);
newOutput.deleteOnExit();
// Delete the temporary file now
System.out.println( "Success of delete: " + newOutput.delete() );