zoukankan      html  css  js  c++  java
  • 读写ZIP文件

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

  • 相关阅读:
    python流行的原因
    shell rename directory
    shell if [ -d filename]
    eclipse文本编码格式修改为UTF-8
    egrep 第几列开始
    Java double 精度
    BigDecimal 两种方式
    使用SecureCRT连接ubuntu
    eclipse快速查找一个变量、方法或者类被引用的地方
    我的互联网金融行业经验总结
  • 原文地址:https://www.cnblogs.com/Defry/p/4576914.html
Copyright © 2011-2022 走看看