代码为groovy代码 参数1为zip文件存放的路径 参数2为文件路径的list
def static packZip(src,fileList){
byte[] buf = new byte[1024]
int readLen=0
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(src));
fileList.each{
def file = new File(it)
def zip = new ZipEntry(file.getName())
zip.setSize(file.length())
zip.setTime(file.lastModified());
zos.putNextEntry(zip);
InputStream is=new BufferedInputStream(new FileInputStream(file))
while ((readLen=is.read(buf, 0, 1024))!=-1) {
zos.write(buf, 0, readLen);
}
is.close();
}
zos.close();
}