posts - 495,  comments - 11,  trackbacks - 0
          import java.io.*;
          import java.util.zip.*;
          public class ZipCompress
          {
          public static void main(String[] args)
          {
          ?? try
          ?? {
          ??? //建立輸出文件流
          ??? FileOutputStream fileOut=
          ???? new FileOutputStream("Example.zip");
          ??? //建立冗余驗證流
          ??? CheckedOutputStream checkedOut=
          ???? new CheckedOutputStream(fileOut,new CRC32());
          ??? //建立Zip流
          ??? ZipOutputStream zipOut=
          ???? new ZipOutputStream(
          ????? new BufferedOutputStream(checkedOut));
          ??? //設(shè)置注釋內(nèi)容
          ??? zipOut.setComment("This is a java zipping test file");
          ??? //文件名
          ??? String fileName=
          ???? "D:/kk/"+"mm.txt"; //文件路徑(最好是全英文字符)
          ??? //讀取被壓速文件流
          ??? BufferedReader in=
          ???? new BufferedReader(new FileReader(fileName));
          ??? //建立壓縮實體
          ??? zipOut.putNextEntry(new ZipEntry(fileName));
          ??? int ch;
          ??? //當被壓縮文件沒有結(jié)束時繼續(xù)讀寫
          ??? while ((ch=in.read())!=-1)
          ??? {
          ???? zipOut.write(ch);
          ??? }
          ??? //關(guān)閉文件流,釋放資源
          ??? in.close();
          ??? zipOut.close();
          ?? }
          ?? catch (IOException e)
          ?? {
          ??? System.out.println(e.toString());
          ?? }
          }
          }
          posted on 2007-06-18 19:21 jadmin 閱讀(59) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 雷州市| 南澳县| 镇江市| 富宁县| 合水县| 什邡市| 石泉县| 丹阳市| 遵化市| 林周县| 拉萨市| 炎陵县| 夏津县| 罗田县| 江油市| 康定县| 潢川县| 五河县| 葵青区| 宜宾市| 龙江县| 三原县| 辽宁省| 桐梓县| 金山区| 措美县| 涞水县| 卢氏县| 化德县| 宣汉县| 巍山| 新巴尔虎右旗| 大城县| 南昌县| 章丘市| 涟源市| 小金县| 兰考县| 鹤峰县| 郓城县| 福州市|