• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert OutputStream to byte[]

 
Bignpsf
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I�m trying to make a download of a zip file, and the return of the method that makes the zip is an ZipOutputStream, and the ServletOutputStream takes in it�s write() method an byte[], i�ve try to convert into an ByteArrayOutputStream but exception ClassCastException is raised.

please help!!!
cheers
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are having trouble with the concept of streams in Java. Not unusual. Check here for a tutorial
In your case, what you want to do is create a ZipOutputStream by passing the ServletOutputStream instance to the ZipOutputStream's constructor. This will compress whatever you send to the client. Create a ZipEntry instance using the name of the file you want to compress and call putNextEntry() on the ZipOutputStream. Write your file to the ZipOutputStream, flush and close.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!