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

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

          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 胡鵬 閱讀(1298) 評論(0)  編輯  收藏 所屬分類: java基礎J2EE

          導航

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

          統(tǒng)計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          agile

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 临泉县| 克拉玛依市| 镇康县| 波密县| 安图县| 南木林县| 门源| 保德县| 平顺县| 承德市| 东丽区| 视频| 施甸县| 普安县| 吉水县| 巨野县| 博野县| 改则县| 海伦市| 韩城市| 邹平县| 沙雅县| 金湖县| 甘泉县| 时尚| 灌云县| 德江县| 文水县| 临朐县| 新野县| 延川县| 葵青区| 陕西省| 酒泉市| 新晃| 铜川市| 万州区| 嘉祥县| 东海县| 陵川县| 榆林市|