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

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 左权县| 图木舒克市| 灵璧县| 阳东县| 会同县| 根河市| 县级市| 江源县| 宜春市| 胶州市| 蒙山县| 潞西市| 荣昌县| 神农架林区| 泌阳县| 大丰市| 滨州市| 濉溪县| 荃湾区| 宾阳县| 安丘市| 方山县| 绥江县| 武宁县| 海晏县| 汶上县| 社会| 新龙县| 卫辉市| 大荔县| 五台县| 遂平县| 曲松县| 富裕县| 随州市| 桐柏县| 岐山县| 崇信县| 甘南县| 乌兰浩特市| 临澧县|