String zipFile = /D:/+ ".zip";
   StringOperator.zip(filePath, zipFile);
   InputStream is = null;
   OutputStream os = null;
   BufferedInputStream bis = null;
   BufferedOutputStream bos = null;
   try {
    response.setCharacterEncoding("utf-8");
    response.addHeader("Content-disposition", "attachment;filename=" + folderFileName + ".zip");
    is = new FileInputStream(zipFile);
    bis = new BufferedInputStream(is);
    os = response.getOutputStream();
    bos = new BufferedOutputStream(os);
    
    int read = 0;
    byte[] bytes = new byte[8072];
    while((read = bis.read(bytes, 0, bytes.length)) != -1){
     bos.write(bytes, 0, read);
    }
    bos.flush();
   } catch (Exception e) {
    e.printStackTrace();
   }finally{
    bos.close();
    os.close();
    bis.close();
    is.close();
   }

/** 
     * 压缩 
     *  
     * @param sourceFile 
     *            压缩的源文件 如: c:/upload 
     * @param targetZip 
     *            生成的目标文件 如:c:/upload.zip 
     */ 
    public static void zip(String sourceFile,String targetZip){  
          
          Project prj = new Project();  
            
          Zip zip = new Zip();  
            
          zip.setProject(prj);  
            
          zip.setDestFile(new File(targetZip));//设置生成的目标zip文件File对象  
            
          FileSet fileSet = new FileSet();  
            
          fileSet.setProject(prj);  
            
          fileSet.setDir(new File(sourceFile));//设置将要进行压缩的源文件File对象 
            
          zip.addFileset(fileSet);  
 
          zip.execute();  
 
    }

读写ZIP文件的更多相关文章

  1. python读写zip文件

    zipfile.ZipFile(fileName[, mode[, compression[, allowZip64]]]) fileName是没有什么疑问的了. mode和一般的文件操作一样,'r' ...

  2. 【.NET深呼吸】Zip文件操作(2):动态生成Zip文档

    通过前面一篇烂文的介绍,大伙儿知道,ZipArchive类表示一个zip文档实例,除了用上一篇文章中所列的方法来读写zip文件外,还可以直接通过ZipArchive类,动态生成zip文件. 文件流操作 ...

  3. JAVA核心技术I---JAVA基础知识(二进制文件读写和zip文件读写)

    一:二进制文件读写 (一)写文件 –先创建文件,写入数据,关闭文件 –FileOutputStream, BufferedOutputStream,DataOutputStream –DataOutp ...

  4. 读写ZIP&JAR文件

    1. ZipEntry 是包括目录的,也就是目录也被当做是一个单独的Entry,在列出它下面的文件之前先列出这个directory entry. 这个在解压ZIP文件的的时候特别有用,我们要先创建这个 ...

  5. 【.NET深呼吸】Zip文件操作(1):创建和读取zip文档

    .net的IO操作支持对zip文件的创建.读写和更新.使用起来也比较简单,.net的一向作风,东西都准备好了,至于如何使用,请看着办. 要对zip文件进行操作,主要用到以下三个类: 1.ZipFile ...

  6. Orchard官方文档翻译(三) 通过zip文件手动安装Orchard

    原文地址:http://docs.orchardproject.net/Documentation/Manually-installing-Orchard-zip-file 想要查看文档目录请用力点击 ...

  7. PHP 解压zip文件的函数封装

    /** * zip文件解压 * * @param $zipFilePath zip文件的路径,可以不加zip文件后缀.如果其他类型的文件伪装成zip解压也会失败 * @param $directory ...

  8. Python使用openpyxl读写excel文件

    Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...

  9. Android 解压zip文件你知道多少?

    对于Android常用的压缩格式ZIP,你了解多少? Android的有两种解压ZIP的方法,你知道吗? ZipFile和ZipInputStream的解压效率,你对比过吗? 带着以上问题,现在就开始 ...

随机推荐

  1. 详解MySQL大表优化方案( 转)

    当MySQL单表记录数过大时,增删改查性能都会急剧下降,可以参考以下步骤来优化: 单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型 ...

  2. Hub, bridge, switch, router, gateway的区别

    这些概念性的东西,其实,有的区别不是很大,有的区别很大. Hub 就是一个重复转发器,就是从一个port接受到数据后,就会原样的向其他的所有端口发送刚才收到的数据.个人理解为是工作在物理层的东西.但是 ...

  3. HTML <div> 和 <span>

    可以通过 <div> 和 <span> 将 HTML 元素组合起来. HTML 块元素 大多数 HTML 元素被定义为块级元素或内联元素. 编者注:“块级元素”译为 block ...

  4. Jaxb笔记

    摘自: http://www.blogjava.net/eagle-daiq/archive/2012/01/30/369016.html 最近项目原因,研究了下jaxb.jaxb是Java api ...

  5. 异步I/O编程实例,异步socket

    下载地址: http://files.cnblogs.com/badnewfish/RUYEESocket.rar ———————————————————————————————————————— 举 ...

  6. c#.net 调用BouncyCastle生成PEM格式的私钥和公钥

    RsaKeyPairGenerator r = new RsaKeyPairGenerator(); r.Init()); AsymmetricCipherKeyPair keys = r.Gener ...

  7. HackerRank "Chocolate in Box" !

    XOR -> 0 is the key (make it even pair): http://www.cnblogs.com/lautsie/p/3908006.html Something ...

  8. LintCode "Maximum Gap"

    Bucketing! A lot of details to take care. struct Bucket { Bucket() :l(-), r(-), bValid(false){}; int ...

  9. WSUS目录本地迁移

    生产环境中有一台win2003 server,安装了Microsoft Windows Server Update Services 3.0,作为所有windows server的内网补丁更新服务器, ...

  10. event 关键字

    event(C# 参考) event 关键字用于在发行者类中声明事件.下面的示例演示如何声明和引发将 EventHandler 用作基础委托类型的事件. C# public class SampleE ...