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;  
           
                     //讀入需要下載的文件的內容,打包到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 閱讀(1312) 評論(0)  編輯  收藏

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


          網站導航:
           
          <2009年12月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 观塘区| 任丘市| 琼海市| 万山特区| 吉林省| 玉林市| 鲜城| 兰西县| 蒙阴县| 陆河县| 赤水市| 安泽县| 简阳市| 改则县| 清河县| 河曲县| 洮南市| 阿荣旗| 民勤县| 改则县| 长宁县| 新乡县| 苏尼特右旗| 五原县| 德保县| 侯马市| 岳阳市| 天祝| 海丰县| 大同县| 韶山市| 丁青县| 阳新县| 连州市| 游戏| 托克托县| 龙江县| 界首市| 东至县| 巴林左旗| 集贤县|