import java.io.*;
import java.util.zip.*;
public class Example4 {
//writing a zip archive
static ZipOutputStream myZOS;
public static void main(String args[]) {
myZOS = new ZipOutputStream (
new BufferedOutputStream(
new FileOutputStream("code.zip")));
writeOneFile("Example1.java");
writeOneFile("Example2.java");
writeOneFile("Example3.java");
myZOS.close();
}
static void writeOneFile(String name) throws IOException {
ZipEntry myZE = new ZipEntry(name);
myZOS.putNextEntry(myZE);
BufferedReader myBR = new BufferedReader(new FileReader(name));
int c;
while((c = myBR.read()) != -1)//read a char until EOF
myZOS.write(c);
myBR.close();
}
}