• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delete file on server after user opens/saves it  RSS feed

 
reethu shivanna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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();
}


}

}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!