Here you can find the source of encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files)
private static void encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files)
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static void encode(String prefix, byte[] buf, ZipOutputStream zos, File[] files) { for (File f : files) { try { if (f.isDirectory()) { encode(prefix, buf, zos, f.listFiles()); } else { ZipEntry entry = new ZipEntry(f.getPath().replace(prefix, "").replace('\\', '/')); zos.putNextEntry(entry); try (InputStream is = new BufferedInputStream(new FileInputStream(f))) { for (;;) { int len = is.read(buf); if (len < 0) break; zos.write(buf, 0, len); }//w ww.j a va 2 s . com } } } catch (Exception e) { throw new RuntimeException(); } } } }