jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Empty Downloaded zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Empty Downloaded zip file" Watch "Empty Downloaded zip file" New topic

Empty Downloaded zip file

Amy Hafer

Joined: Mar 29, 2001
Posts: 6
I am new to this site but it is by far the most user friendly I have been to. Hoping you can help..
I am writing a servlet that sends a zip file to the user of some files that he/she requested. I am able to create the zip file and write the correct entries to it on the server but all that is available for download is an empty zip file. I think I have major problems understanding output streams.
I was using the
ServletOutputStream out=response.getOutputStream();
I have also tried
PrintWriter out = new PrintWriter(response.getOutputStream());
then I thought all you need is to start the response:
response.setHeader("Content-Disposition","attachment;filename=" + thefile.getName());
but I don't know how to take the ZipOutputStream or is it the FileOutputStream and send it via out.println()
Any help would be most appreciated!!!
It is sorta covered in the JavaRanch Style Guide.
subject: Empty Downloaded zip file