将多个文件用zip打包
用法: 先用javac编译,后用java ZipCompress1 a.rpm b.rpm c.rpm, 最终打包成testm.zip文件
import java.util.*;
import java.util.zip.*;
import java.io.*;
public class ZipCompress1 {
public static void main(String[] args) {
try {
FileOutputStream f = new FileOutputStream( "testm.zip");
ZipOutputStream out = new ZipOutputStream( new DataOutputStream(f));
for ( int i = 0; i < args.length; i++) {
System.out.println( "Writing file " + args[i]);
DataInputStream in =
new DataInputStream( new FileInputStream(args[i]));
out.putNextEntry( new ZipEntry(args[i]));
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/250079,如需转载请自行联系原作者