I have Download functionality in my application. The function download the file in .xls format and zipped it. So that user can save that zip file on this local machine.
Everything workign fine but the file which is zipped inside have no extension. Example I am expeting the user to download xyz.zip file which interns contains xyz.xls,but unfortunately file having no extension (downloaded as xyz) inside xyz.zip.I am using below statement to zip the file.
You might want to check the code you posted. There's no mention of ZipOutputStream, or zipping at all. It also doesn't contain the sample lines you had in your original post, which look like they come from a servlet doGet() or doPost() method.
Always close the outer-most stream. That should also close the stream it was wrapping. In this case it's very, very important to close the ZipOutputStream before you close the FileOutputStream, as the ZipOutputStream will write some extra bytes to close the ZIP file itself. If you close the FileOutputStream first those bytes will be missing and the ZIP file will be corrupt.
Joined: May 30, 2007
In below code snippet you are saying I need to close zipOutputStreamObject beore fileInputStreamObject?
Rob Spoor wrote:Also, what did I tell you about closing the FileInputStream before closing the ZipOutputStream?
Actually, you said not to close a FileOutputStream before you close a ZipOutputStream that wraps it. Anand asked you about that specifically a couple of posts ago because he's wrapping the servlet's output stream, not a FileOutputStream, but is using a FileInputStream to read the file. I don't think it matters when you close the Input Stream as long as you've finished reading from it. However, I also don't see anything that would cause the "double zip" issue Anand is seeing.
I think Wouter meant that if an exception happens at zipOutputStreamObject.closeEntry(), your program will jump immediately to the the catch block, bypassing the fileInputStreamObject.close() and zipOutputStreamObject.close(). You should really put each close into its own try-catch block or use one of those closeQuietly() utility methods. It's a bigger deal when you're closing something like a database connection or other scarce resources. I've seen server slow down and stop because there just aren't any db connections left ... and all because the close wasn't handled properly when an exception occurred.
I'm glad you solved your problem. Can you post the code here? Then we can mark the thread as resolved, and anyway I'm curious where the error was.
Joined: May 30, 2007
The issue was with contentType
Instead of response.setContentType("application/zip"); I read some where in Microsoft site and tried below and isssue disappeared:
So it is some what specific for IE and I am still clueless about this issue.
subject: Issue with Download using ZipOutputStream