• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Delete file on server after user opens/saves it

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a JSP page which onClick will display file from a location on server ... I need to delete those temp files.
I tried to use file.delete() it failed as file becomes unavailable once user opens the file.

The code snippet is as follows:

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
String result = (String) session.getAttribute("file");
File f = new File("/hosting/apps/temp");
if (null != result) {


String download = (String) session.getAttribute("download");
String refresh = (String) session.getAttribute("refresh");
if (download.equalsIgnoreCase("download")) {
response.setHeader("Content-disposition", "attachment; filename=" + result);
}else if(refresh.equalsIgnoreCase("refresh")){
if(f.exists()){
//but f.exists is false ,so not able to delete file
f.delete();
}


}

}
}
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic