<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 鋒出磨礪 閱讀(903) 評論(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
    能用嗎?
    主站蜘蛛池模板: 亚洲A∨无码无在线观看| 亚洲区视频在线观看| 最近2019免费中文字幕视频三| 亚洲视频在线观看不卡| 在线日韩av永久免费观看| eeuss影院免费92242部| 久久亚洲中文字幕精品有坂深雪 | 最近中文字幕无吗高清免费视频| 国产成人精品亚洲一区| 亚洲国产精品无码成人片久久| 青青草免费在线视频| 人人爽人人爽人人片av免费| 亚洲成aⅴ人片在线影院八| 免费人成激情视频| 波多野结衣在线免费视频| 日韩在线视频线视频免费网站| 亚洲老熟女@TubeumTV| 国产一级做a爱免费视频| 99久在线国内在线播放免费观看| 狼人大香伊蕉国产WWW亚洲| 91嫩草私人成人亚洲影院| 亚洲精品国产精品国自产观看 | 国产va免费观看| 亚洲jjzzjjzz在线观看| 亚洲第一AV网站| 免费人成激情视频| 一区二区无码免费视频网站| 免费一级全黄少妇性色生活片 | 免费观看一区二区三区| 暖暖在线视频免费视频| 狼人大香伊蕉国产WWW亚洲| 亚洲神级电影国语版| 在线亚洲精品福利网址导航| 成在线人永久免费视频播放| 最近最新高清免费中文字幕| 一区二区三区在线免费观看视频 | 含羞草国产亚洲精品岁国产精品| 666精品国产精品亚洲| 亚洲精品无码MV在线观看| 免费中文字幕在线观看| 好男人看视频免费2019中文 |