Posted By

nialace on 05/31/11


Tagged

file java


Versions (?)

Create Zip file in memory


 / Published in: Java
 

URL: http://tripoverit.blogspot.com/2008/04/java-create-zip-file-in-memory.html

  1. private static byte[] createZip(Map files) throws IOException {
  2. ZipOutputStream zipfile = new ZipOutputStream(bos);
  3. Iterator i = files.keySet().iterator();
  4. String fileName = null;
  5. ZipEntry zipentry = null;
  6. while (i.hasNext()) {
  7. fileName = (String) i.next();
  8. zipentry = new ZipEntry(fileName);
  9. zipfile.putNextEntry(zipentry);
  10. zipfile.write((byte[]) files.get(fileName));
  11. }
  12. zipfile.close();
  13. return bos.toByteArray();
  14. }

Report this snippet  

You need to login to post a comment.