java压缩zip文件中文乱码问题

1:jar包 
commons-compress-1.0.jar 
commons-io.jar 

import org.apache.commons.compress.archivers.ArchiveEntry; 
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; 
import org.apache.commons.io.IOUtils; 

2:代码片段: 

ZipArchiveInputStream zais = new ZipArchiveInputStream(zipFileForm.getInputStream(), "GBK", true); 
ArchiveEntry archiveEntry = null; 
while((archiveEntry = zais.getNextEntry()) != null) { 
//获取文件名 
String entryFileName = archiveEntry.getName(); 
//只处理包中的*.xls文件 
if(!entryFileName.endsWith(".xls")){ 
continue; 
} 
// 把解压后的数据写到内存数组中. 
ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
IOUtils.copy(zais, baos); 

//把解压后的内存数组与ByteArrayInputStream关联 
ByteArrayInputStream oneUnzipedIS = new ByteArrayInputStream(baos.toByteArray()); 
}

 

posted @ 2014-12-25 16:21  letmedown  阅读(1431)  评论(0)    收藏  举报