- From: Eddy <pai990_2000@yahoo.com>
- Date: Tue, 8 May 2001 14:10:31 -0400 (EDT)
- To: <www-jigsaw@w3.org>
Hello Buddy I am writing a program for downloading file by using servlet. I have encounted a problem. I set the response.setHead() in the program. Also I use the response.getOutputStream() from writing file. When I click the "start download" button, a popup window occurs. In the window, user got two options(open or save). If user click ok for save, the second popup window occurs. It asks user to choose the directory. But, when I click the "Cancel" or "X" on the top of the window. The downloading file is locked in my computer. I can not do anything for the file. I thought because I did not close the outputstream. But, in my program, I do use the catch(Throwable e).But, I still can not catch it. Do you have any ideas about that. I will be appreicated it //////////////////////////////////////////////////////////////////////////// ///// try { int size = 0; response.setContentType("application/octet-stream"); resp.setHeader("Content-Disposition", "attachment; filename=\"" +_file.getName()+ "\";"); response.setHeader("Content-length", (new Long(fileSize)).toString()); response.setHeader("Cache-Control", "no-cache"); ServletOutputStream stream = response.getOutputStream(); java.io.File target = new java.io.File(fileName); BufferedInputStream fif = new BufferedInputStream(new FileInputStream(target)); int data; int downloadedSize = 0; int downloadSeccess = 1; try{ while((data = fif.read()) != -1) { downloadedSize+=data; stream.write(data); } fif.close(); stream.close(); } catch(Throwable e){ fif.close(); stream.close(); } //////////////////////////////////////////////////////////////////////////// /// Thanks a lot Eddy
Received on Wednesday, 9 May 2001 07:19:28 UTC