This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Delete file on server after user opens/saves it Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Delete file on server after user opens/saves it" Watch "Delete file on server after user opens/saves it" New topic
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();
}


}

}
}
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Delete file on server after user opens/saves it
 
Similar Threads
JSP Reload in opening attachment
Close browser window
Removing temporary files
Download File
Refresh problem in JSP page