滿店香的家

          學(xué)習(xí)+實(shí)踐=進(jìn)步

          使用commons-compress包對(duì)tar.gz文件進(jìn)行解壓處理

              想使用commons-compress-1.4.1.jar對(duì)tar.gz文件進(jìn)行處理,上網(wǎng)找半天,別人寫(xiě)的都很費(fèi)勁,看了看樣例,自己寫(xiě)了一個(gè)方法。
           /**
            * 解壓tar.gz文件
            * tar文件只是把多個(gè)文件或文件夾打包合成一個(gè)文件,本身并沒(méi)有進(jìn)行壓縮。gz是進(jìn)行過(guò)壓縮的文件。
            * @param dir
            * @param filepath
            * @throws Exception
            */
           public static void deGzipArchive(String dir, String filepath)
             throws Exception {
            final File input = new File(filepath);
            final InputStream is = new FileInputStream(input);
            final CompressorInputStream in = new GzipCompressorInputStream(is, true);
            TarArchiveInputStream tin = new TarArchiveInputStream(in);
            TarArchiveEntry entry = tin.getNextTarEntry();
            while (entry != null) {
             File archiveEntry = new File(dir, entry.getName());
             archiveEntry.getParentFile().mkdirs();
             if (entry.isDirectory()) {
              archiveEntry.mkdir();
              entry = tin.getNextTarEntry();
              continue;
             }
             OutputStream out = new FileOutputStream(archiveEntry);
             IOUtils.copy(tin, out);
             out.close();
             entry = tin.getNextTarEntry();
            }
            in.close();
            tin.close();
           }

          遺留問(wèn)題:

           tar解壓tar.gz文件時(shí),中文文件夾有亂碼
           研究發(fā)現(xiàn)commpress包解壓時(shí),TarArchiveInputStream類對(duì)中文未做處理,進(jìn)一步跟蹤,第一層是

          utf8,正確,往下取,需要包括子文件夾,子文件,涉及到"/"等符號(hào)的切割,這個(gè)地方未考慮中文
          據(jù)說(shuō)ant沒(méi)問(wèn)題

          posted on 2012-06-15 12:12 滿店香 閱讀(6832) 評(píng)論(1)  編輯  收藏

          Feedback

          # re: 使用commons-compress包對(duì)tar.gz文件進(jìn)行解壓處理 2012-06-15 12:16 ppt模板下載

          可以去加壓后再看看的  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 廊坊市| 顺义区| 宽甸| 邵阳市| 唐海县| 资兴市| 鲁甸县| 奉节县| 河源市| 台山市| 大同市| 璧山县| 建德市| 揭西县| 开远市| 宁蒗| 岱山县| 雷波县| 冕宁县| 永登县| 开远市| 祁阳县| 光山县| 九龙坡区| 桐乡市| 积石山| 尉犁县| 历史| 微博| 宽甸| 尼玛县| 新沂市| 安徽省| 加查县| 新邵县| 仁布县| 舒兰市| 松潘县| 临猗县| 大余县| 安塞县|