现在的位置: 首页 > 综合 > 正文

打包zip

2012年12月12日 ⁄ 综合 ⁄ 共 470字 ⁄ 字号 评论关闭
代码为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();
    } 

抱歉!评论已关闭.