This content has been marked as final. Show 4 replies
Yes, that last line of code does delete the file.
But what's this "download" thing you're talking about? Misunderstanding how that works might be the source of your problem, so you should really explain what it is.
Okay, yes you're right.
The excel piece of code is:
This reflects where the file will write out to....
+workbook = Workbook.createWorkbook(new File("C:\\file_output\\"+output));+
Then I have loads of code to set up the headings and what goes in each cell of the spreadsheet.
Then I have
then I have the download piece.
Immediately after that I have the code I originally listed.
Your file is now ready to be <A href="./file_output/<%=output%>"> downloaded </a>
It seems I need to have a IF statement or something to tell it Only delete when the application is closed....but I don't know how to do that.
Oh, I see. You are generating this file on the server, then sending a link to the client so that he or she can download the file.
And your problem is that you want to wait until the client downloads the file before you delete it. But think about it: you send the link to the client. The client may have gone for lunch and may not download it for an hour. The client may have changed his/her mind and is NEVER going to download it.
So, you can't have your code wait for the client to download the file. If you really want to persist in generating a file for the client to download, then your best bet is to not delete it in your code at all. Instead, have some process which runs periodically and deletes "download files" which are more than a couple of days old.
But a better bet is to not generate a file at all. Instead, generate the spreadsheet and return that as the response, instead of returning HTML with a link. Then there aren't any files cluttering up your server. Google for "file download servlet" and you should find examples of how to do that.
Excellent. I will try that. I could just run a daily cron job to delete the files if I don't find a better solution. Of course I have to look up how to do a cron job, lol.
I'll do some more research.