Java builds zip compressed files

zhaozj2021-02-08  396

Import java.io. *;

Import java.util.zip. *;

Class zip {

public

Static

Void main (String args [])

THROWS IOEXCEPTION {

Byte b [] =

New

Byte [512];

ZipOutputStream Zout =

New ZipOutputStream (System.out);

FOR

INT i = 0; i

InputStream in =

New fileInputstream (args [i]);

ZIPENTRY E =

New Zipentry (args [i] .replace (file.separatorchar, '/'));

Zout.putNextentry (e);

INT LEN = 0;

While ((len = IN.READ (b))! = -1) {

Zout.write (B, 0, LEN);

}

Zout.Closeentry ();

Print (e);

}

Zout.Close ();

}

public

Static

Void Print (ZIPENTRY E) {

PRINTSTREAM ERR = System.err;

Err.Print

"Added" E.GetName ());

IF (E.getMethod () == ZiPENTRY.DEFLED) {

Long size = E.GETSIZE ();

IF (size> 0) {

Long csize = E.GetCompRessedSize ();

Long Ratio = (Size-Csize) * 100) / size;

Err.Println

"(Deflated" Ratio

"%)");

}

Else {

Err.Println

"(DEFLED 0%)");

}

}

Else {

Err.Println

"(stored 0%)");

}

}

}

v

转载请注明原文地址:https://www.9cbs.com/read-866.html

New Post(0)