<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一切皆可抽象

    大而無形 庖丁解牛 厚積薄發 滌慮玄覽
       ::  ::  ::  ::  :: 管理

    【原創】java寫的壓縮、解壓的代碼

    Posted on 2005-10-28 15:04 鋒出磨礪 閱讀(907) 評論(2)  編輯  收藏 所屬分類: java算法

    import java.io.*;
    import java.util.*;
    import java.util.zip.ZipOutputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;

    public class FileMgr {
      public FileMgr() {
      }
     /**
       * 壓縮文件
       * @param srcfile File[]  需要壓縮的文件列表
       * @param zipfile File    壓縮后的文件
       */
      public static void ZipFiles(java.io.File[] srcfile, java.io.File zipfile) {
        byte[] buf = new byte[1024];
        try {
          // Create the ZIP file
          ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
          // Compress the files
          for (int i = 0; i < srcfile.length; i++) {
            FileInputStream in = new FileInputStream(srcfile[i]);
            // Add ZIP entry to output stream.
            out.putNextEntry(new ZipEntry(srcfile[i].getName()));
            // Transfer bytes from the file to the ZIP file
            int len;
            while ( (len = in.read(buf)) > 0) {
              out.write(buf, 0, len);
            }
            // Complete the entry
            out.closeEntry();
            in.close();
          }
          // Complete the ZIP file
          out.close();
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }

      /**
       * 解壓縮
       * @param zipfile File 需要解壓縮的文件
       * @param descDir String  解壓后的目標目錄
       */
      public static void UnZipFiles(java.io.File zipfile, String descDir) {
        try {
          // Open the ZIP file
          ZipFile zf = new ZipFile(zipfile);
          for (Enumeration entries = zf.entries(); entries.hasMoreElements(); ) {
            // Get the entry name
            ZipEntry entry = ( (ZipEntry) entries.nextElement());
            String zipEntryName = entry.getName();
            InputStream in = zf.getInputStream(entry);
           // System.out.println(zipEntryName);
            OutputStream out = new FileOutputStream(descDir + zipEntryName);
            byte[] buf1 = new byte[1024];
            int len;
            while ( (len = in.read(buf1)) > 0) {
              out.write(buf1, 0, len);
            }
            // Close the file and stream
            in.close();
            out.close();
          }
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }

    }


    評論

    # re: 【原創】java寫的壓縮、解壓的代碼  回復  更多評論   

    2006-05-16 15:03 by whw
    guanyong ma

    # re: 【原創】java寫的壓縮、解壓的代碼  回復  更多評論   

    2006-05-16 15:04 by whw
    能用嗎?
    主站蜘蛛池模板: 巨波霸乳在线永久免费视频| 国产AV无码专区亚洲Av| 国产亚洲美女精品久久久久狼 | 6080午夜一级毛片免费看6080夜福利| 亚洲精品无码成人片在线观看 | WWW国产成人免费观看视频| 亚洲精品无码99在线观看| eeuss影院www天堂免费| 国产性爱在线观看亚洲黄色一级片| 无码精品人妻一区二区三区免费| 免费va在线观看| 国产精品美女免费视频观看| 国产亚洲综合成人91精品| 一级毛片免费毛片一级毛片免费| 国产精品亚洲美女久久久| 亚洲日韩人妻第一页| 99爱视频99爱在线观看免费| 亚洲国产成人久久综合| 在线观看成人免费| 亚洲AV日韩综合一区| 亚洲A丁香五香天堂网| 99免费精品视频| 亚洲精品国产福利片| 啦啦啦中文在线观看电视剧免费版 | 麻豆最新国产剧情AV原创免费| 一本色道久久综合亚洲精品蜜桃冫| 无码国模国产在线观看免费| 人禽伦免费交视频播放| 久久夜色精品国产亚洲| 无人在线观看完整免费版视频| 狼色精品人妻在线视频免费| 亚洲AV无码第一区二区三区| AV免费网址在线观看| jizz在线免费播放| 亚洲熟妇av一区二区三区下载| 亚洲avav天堂av在线网毛片| 国产亚洲精品无码成人| 久久精品亚洲精品国产色婷| 亚洲精品中文字幕乱码三区| 亚洲电影免费观看| 国产精品亚洲专区无码不卡|