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

Delete file on server after user opens/saves it

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

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")){
//but f.exists is false ,so not able to delete file


They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic