Herrameinta sencilla para crear un archivo zip

JAVA:
  1. /*
  2. ** a simple ZIP tool
  3. ** Réal Gagnon
  4. ** ex.  java Zip file.1 file.2> file.zip
  5. **
  6. */
  7. import java.io.*;
  8. import java.util.zip.*;
  9.  
  10. class Zip {
  11.   public static void main(String args[]) throws IOException {
  12.     byte b[] = new byte[512];
  13.     ZipOutputStream zout = new ZipOutputStream(System.out);
  14.     for(int i = 0; i <args.length; i ++) {
  15.       InputStream in = new FileInputStream(args[i]);
  16.       ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar,'/'));
  17.       zout.putNextEntry(e);
  18.       int len=0;
  19.       while((len=in.read(b)) != -1) {
  20.         zout.write(b,0,len);
  21.         }
  22.       zout.closeEntry();
  23.       print(e);
  24.       }
  25.     zout.close();
  26.     }
  27.    
  28.   public static void print(ZipEntry e){
  29.     PrintStream err = System.err;
  30.     err.print("added " + e.getName());
  31.     if (e.getMethod() == ZipEntry.DEFLATED) {
  32.       long size = e.getSize();
  33.       if (size> 0) {
  34.         long csize = e.getCompressedSize();
  35.         long ratio = ((size-csize)*100) / size;
  36.         err.println(" (deflated " + ratio + "%)");
  37.         }
  38.       else {
  39.         err.println(" (deflated 0%)");
  40.         }
  41.       }
  42.     else {
  43.       err.println(" (stored 0%)");
  44.       }
  45.     }
  46. }

Popularidad: 38%