File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing temporary files

 
K Gupta
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I am posting at right place, so my apologies if its not

I have a problem regarding removing my temporary files once they are sendt to or viewed by the client.Now I can't call delete afetr sending because I don't know till when the user clicks the save button.So I need some way to figure that out .Please help.

Thax in advance.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of application is this? A Swing app? A Web app?

If it's a Swing app, mark the files as temporary files -- look at the java.io.File class for this. Marked files will be deleted automatically when the JVM exits.

If it's a Web app, you can't delete files on the user's machine.
 
K Gupta
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a web -app and I want to delete file from the server after user has downloaded it
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use a servlet in my web app to provide the file, after the file is viewed the servlet will delete it. Lets say you generate a timestamp.pdf file on the server in an specific place. You will give the user a link to the servlet and pass the servlet the timestamp (or file id) via a parameter. Then the servlet will get the file, open it with a inputstream and print it to the response.outputstream. At the end you flush the outputstream and delete the file.

This will clean up your temp files. But user can only download them once. If they try a second time they will cause an exception cause the file was deleted at the end of the first use. If this is a problem tell me, there is a second solution to the problem but maybe it will need some changes to your app.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic