TrueZIP使用過程中遇到的問題記錄

           

          最近有Java解壓縮的需求,java.util.zip實在不好用,對中文支持也不行。所以選擇了強大的TrueZIP,使用時遇到了一個問題,做個記錄。
          解壓縮代碼如下:

          ArchiveDetector detector = new DefaultArchiveDetector(ArchiveDetector.ALL,
                  new Object[] { "zip", new CheckedZip32Driver("GBK") } );
          File zipFile = new File("zipFile", detector);
          File dst = new File("dst");
          // 解壓縮
          zipFile.copyAllTo(dst);

          代碼十分簡潔,注意這個File是

          de.schlichtherle.io.File

          不是

          java.io.File

          當處理完業務要刪除這個Zip File時,問題出現了:
          這個文件刪不掉!!!
          把自己的代碼檢查了好久,確認沒問題后,開始從TrueZIP下手,發現它有特殊的地方的,是提示過的:

          File file = new File(“archive.zip”); // de.schlichtherle.io.File!
          Please do not do this instead:
          de.schlichtherle.io.File file = new de.schlichtherle.io.File(“archive.zip”);


          This is for the following reasons:
          1.Accidentally using java.io.File and de.schlichtherle.io.File instances referring to the same path concurrently will result in erroneous behaviour and may even cause loss of data! Please refer to the section “Third Party Access” in the package Javadoc of de.schlichtherle.io for for full details and workarounds.
          2.A de.schlichtherle.io.File subclasses java.io.File and thanks to polymorphism can be used everywhere a java.io.File could be used.

          原來兩個File不能交叉使用,搞清楚原因了,加這么一句代碼搞定。

          zipFile.deleteAll();

          posted on 2011-01-11 22:30 胡鵬 閱讀(1304) 評論(0)  編輯  收藏 所屬分類: java基礎J2EE

          導航

          <2011年1月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          agile

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 应城市| 滕州市| 渑池县| 南召县| 资兴市| 太谷县| 普定县| 新乐市| 汝阳县| 蓝田县| 正定县| 天镇县| 微博| 读书| 台中市| 湛江市| 安徽省| 利津县| 崇义县| 山东| 富蕴县| 武定县| 巴中市| 若尔盖县| 灵川县| 长治市| 罗江县| 太原市| 玛纳斯县| 建湖县| 镇雄县| 阿荣旗| 于都县| 筠连县| 曲松县| 张家港市| 兰考县| 察隅县| 夏河县| 玛沁县| 女性|