posts - 64,  comments - 9,  trackbacks - 0

          package com.bjca.ecms.credence.action;

          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;
          import java.util.zip.ZipEntry;
          import java.util.zip.ZipOutputStream;

          public class ZipOutputStreamDemo {
            
            
              public static void main(String[] args) throws Exception {  
           
                 byte[] buffer = new byte[1024];  
           
                 //生成的ZIP文件名為Demo.zip  
           
                 String strZipName = "C:\\temp\\Demo.zip";  
           
                 ZipOutputStream out = new ZipOutputStream(new FileOutputStream(strZipName));  
           
                 //需要同時下載的兩個文件result.txt ,source.txt  
           
                 File[] file1 = {new File("C:\\temp\\temp001.txt"),new File("C:\\temp\\temp002.txt")};  
           
                 for(int i=0;i<file1.length;i++) {  
           
                     FileInputStream fis = new FileInputStream(file1[i]);  
           
                     out.putNextEntry(new ZipEntry(file1[i].getName()));  
           
                     int len;  
           
                     //讀入需要下載的文件的內(nèi)容,打包到zip文件  
           
                    while((len = fis.read(buffer))>0) {  
           
                     out.write(buffer,0,len);   
           
                    }  
           
                     out.closeEntry();  
           
                     fis.close();  
           
                 }  
           
                  out.close();  
           
                  System.out.println("生成Demo.zip成功");  
           
              }  

          }

          posted on 2009-12-09 09:48 super_nini 閱讀(1314) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2009年12月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 喀喇| 石门县| 灵武市| 卢湾区| 垦利县| 克东县| 淮滨县| 宁远县| 常熟市| 垦利县| 丹巴县| 营口市| 蒲江县| 共和县| 宜兰县| 平乡县| 凤山县| 神池县| 佳木斯市| 乐东| 黄浦区| 黔西| 墨玉县| 江达县| 鹤庆县| 韩城市| 五家渠市| 马边| 岳阳县| 阿拉善右旗| 册亨县| 元谋县| 陆丰市| 齐河县| 阿巴嘎旗| 泸西县| 奉贤区| 万源市| 德化县| 安多县| 林周县|