| Author |
Delete file on server after user opens/saves it
|
reethu shivanna
Greenhorn
Joined: Sep 09, 2012
Posts: 3
|
|
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();
}
}
}
}
|
 |
 |
|
|
subject: Delete file on server after user opens/saves it
|
|
|