[JAVA_Apache]使用commons compress套件,使用壓縮檔zip、解壓縮unZip java.util.zip無法處理與中國,日本,Unicode字符的文件名稱 使用commons compress套件 可以解決使用java.util.zip套件作壓縮時,為什麼中文檔名都會變亂碼的問題 是java 的bug java bug_id 4820807 java bug_id 4885817 java bug_id 4244499 技術參考 api Commons Compress 1.5-SNAPSHOT API 取得jar apache compress 官網 maven examples apache examples 簡單的測試程式

package com.test;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;

public class ZipTest {

 public static void main(String[] args)  throws Exception{
  File zipFile = File.createTempFile("zipTest", ".zip");

     FileOutputStream fos = new FileOutputStream(zipFile);    
     ZipArchiveOutputStream aos = new ZipArchiveOutputStream(fos);
     aos.setEncoding("BIG5");
     try {
       ZipArchiveEntry entry = new ZipArchiveEntry("中文解壓測試.txt");
       aos.putArchiveEntry(entry);
       aos.write("中文解壓測試".getBytes());
       aos.closeArchiveEntry();      
     } finally {
       aos.close();
       fos.close();
     }
     //開啟檔案
     Desktop.getDesktop().open(zipFile);    
 }
}

參考  [JAVA_程式分享]使用commons compress套件,使用壓縮檔zip、解壓縮unZip

 

其它文章

文章標籤
全站熱搜
創作者介紹
創作者 PG Levin Li 的頭像
PG Levin Li

程式開發學習之路

PG Levin Li 發表在 痞客邦 留言(0) 人氣(425)