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

          導航

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

          統計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          agile

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 九龙城区| 含山县| 开远市| 武清区| 青岛市| 余干县| 静宁县| 和硕县| 元谋县| 拜城县| 晋宁县| 武威市| 蕉岭县| 上栗县| 黄大仙区| 桃江县| 双江| 平阴县| 绿春县| 沽源县| 常熟市| 司法| 舟山市| 湘乡市| 泾阳县| 乌鲁木齐县| 揭阳市| 巴塘县| 米易县| 金昌市| 巴青县| 老河口市| 府谷县| 喜德县| 湘潭县| 潜山县| 辽宁省| 额济纳旗| 博乐市| 广饶县| 康乐县|