• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Removing temporary files

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a web -app and I want to delete file from the server after user has downloaded it
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Squanch that. And squanch this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic