posts - 22,comments - 35,trackbacks - 0
          ?1 import ?java.util.zip.ZipOutputStream;
          ?2 import ?java.io.IOException;
          ?3 import ?java.util.zip.ZipEntry;
          ?4 import ?java.io.FileOutputStream;
          ?5 import ?java.io.FileInputStream;
          ?6
          ?7 class ?CSVZip? {
          ?8
          ?9 ?? public ? static ? void ?Zip(String?file,String?zipfile)? {
          10 ???? try ? {
          11 ?????? // 創(chuàng)建文件輸入流對象
          12 ??????FileInputStream?in? = ? new ?FileInputStream(file);? // 0
          13 ?????? // 創(chuàng)建文件輸出流對象
          14 ??????FileOutputStream?out? = ? new ?FileOutputStream(zipfile);? // 1
          15 ?????? // 創(chuàng)建ZIP數(shù)據(jù)輸出流對象
          16 ??????ZipOutputStream?zipOut? = ? new ?ZipOutputStream(out);
          17 ?????? // 創(chuàng)建指向壓縮原始文件的入口
          18 ??????ZipEntry?entry? = ? new ?ZipEntry(file);? // 0
          19 ??????zipOut.putNextEntry(entry);
          20 ?????? // 向壓縮文件中輸出數(shù)據(jù)
          21 ?????? int ?nNumber;
          22 ?????? byte []?buffer? = ? new ? byte [ 512 ];
          23 ?????? while ?(?(nNumber? = ?in.read(buffer))? != ? - 1 )
          24 ????????zipOut.write(buffer,? 0 ,?nNumber);
          25 ?????? // 關(guān)閉創(chuàng)建的流對象
          26 ??????zipOut.close();
          27
          28 ??????out.close();
          29 ??????in.close();
          30
          31 ????}
          catch ?(IOException?e)? {
          32 ???????????????System.out.println(e);
          33 ???????????????????????????}

          34
          35 ??}

          36 }

          37
          posted on 2006-06-05 17:06 kelven 閱讀(809) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 恩施市| 贡觉县| 大庆市| 田林县| 永济市| 聂拉木县| 景德镇市| 雅江县| 永靖县| 博野县| 吉林市| 尚志市| 上栗县| 襄樊市| 阜南县| 彰武县| 东乡县| 高邑县| 精河县| 镇坪县| 宁南县| 余江县| 科技| 崇左市| 伊春市| 泾源县| 东明县| 安图县| 仲巴县| 高安市| 五峰| 会昌县| 蒙自县| 平陆县| 缙云县| 贵港市| 金川县| 英德市| 开平市| 洪湖市| 新丰县|