Create a zip file and add one entry in Java
Description
The following code shows how to create a zip file and add one entry.
Example
//from ww w . ja v a 2 s . c om
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("C:/MyZip.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze = new ZipEntry("C:/file1.txt");
zos.putNextEntry(ze);
zos.closeEntry();
ze = new ZipEntry("C:/file2.txt");
zos.putNextEntry(ze);
zos.closeEntry();
zos.close();
}
}