new ZipEntry(String name) : ZipEntry « java.util.zip « Java by API






new ZipEntry(String name)

 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
  public static void main(String[] argv) throws Exception {
    String[] filenames = new String[] { "filename1", "filename2" };
    byte[] buf = new byte[1024];
    String outFilename = "outfile.zip";
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));

    for (int i = 0; i < filenames.length; i++) {
      FileInputStream in = new FileInputStream(filenames[i]);
      out.putNextEntry(new ZipEntry(filenames[i]));
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      out.closeEntry();
      in.close();
    }
    out.close();
  }
}

   
  








Related examples in the same category

1.ZipEntry.DEFLATED
2.ZipEntry.STORED
3.ZipEntry: getCompressedSize()
4.ZipEntry: getComment()
5.ZipEntry: getCrc()
6.ZipEntry: getName()
7.ZipEntry: getSize()
8.ZipEntry: getTime()
9.ZipEntry: isDirectory()