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 閱讀(1314) 評論(0)  編輯  收藏

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


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

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 汝州市| 东方市| 淮南市| 梨树县| 霍林郭勒市| 景洪市| 济阳县| 福州市| 灵山县| 徐汇区| 疏附县| 齐河县| 安平县| 神池县| 习水县| 陆良县| 霍林郭勒市| 萨迦县| 永昌县| 赞皇县| 喀什市| 庄河市| 景泰县| 大同市| 丰台区| 永寿县| 肇庆市| 嘉兴市| 肇州县| 乐平市| 杨浦区| 视频| 衡南县| 通辽市| 冀州市| 尉氏县| 长武县| 明水县| 阳山县| 大化| 宝丰县|