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è)務(wù)要刪除這個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基礎(chǔ)J2EE

          導航

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

          統(tǒng)計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          agile

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 六枝特区| 四川省| 巫溪县| 黄陵县| 怀远县| 罗城| 商丘市| 康定县| 贺兰县| 玉屏| 迁安市| 东阳市| 永昌县| 通江县| 奉节县| 青浦区| 长白| 茂名市| 和龙市| 眉山市| 白玉县| 柳林县| 邛崃市| 阿荣旗| 岳阳县| 遂平县| 乌什县| 亳州市| 来宾市| 油尖旺区| 青铜峡市| 河津市| 安阳市| 元谋县| 深水埗区| 张掖市| 比如县| 开阳县| 岳阳市| 郑州市| 崇仁县|