포장 zip

773 단어
   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();
    } 

좋은 웹페이지 즐겨찾기