Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download to Excel then delete the temp file

843785Dec 31 2008 — edited Dec 31 2008
I 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() );
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 28 2009
Added on Dec 31 2008
4 comments
1,263 views