This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

zip file to client  RSS feed

 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a zip file in my D: folder.Now i need to send it to my client.I did in the following way.
<code>

fileIn = new FileInputStream("D:/files.zip");

input = new ZipInputStream(fileIn);


buf = new BufferedInputStream(input);

ServletOutputStream servletOut = response.getOutputStream();
response.setContentType("application/zip");
response.addHeader("Content-Disposition", "attachment; filename=myZip");

int readBytes = 0;

while ((readBytes = buf.read()) != -1)
servletOut.write(readBytes);
servletOut.flush();
</code>

Am able to get a file with aname myZip but it doesnot contain any files inside.
Can anyone suggest what can be wrong here.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i simply messed up with the code.

got the solution.ZipInputReader is not needed.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you writing to the client a byte at a time?!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!