Skip to Content

In case you need to zip some data, for sending to the client on the fly without intermediary file creation that’s simple as piece of cake:

ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
                                                      ZipOutputStream zipfile = new ZipOutputStream(bos);
                                                      ZipEntry zipentry = new ZipEntry("packedFileName");
                                                      try {
                                                                zipfile.putNextEntry(zipentry);
                                                                zipfile.write("Zipped content".getBytes());
                                                                zipfile.close();
                                                      } catch(IOException e) {
                                                                e.printStackTrace();
                                                      }
byte[] result = bos.toByteArray();

Best wishes,

Max

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply