javazip解壓中文
① 請大神幫忙解決一個用java解壓縮一個zip壓縮格式位元組流中文內容亂碼問題!
這個問題我有點印象,好像是包的問題。好像不能用zip的那個,換另一個包就好了。具體我也不記得了
② 如何在java中實現對zip和rar文件的解壓
java中有zip包,可以使用
publicvoidgetZipFiles(StringzipFile,StringdestFolder)throwsIOException{
BufferedOutputStreamdest=null;
ZipInputStreamzis=newZipInputStream(
newBufferedInputStream(
newFileInputStream(zipFile)));
ZipEntryentry;
while((entry=zis.getNextEntry())!=null){
System.out.println("Extracting:"+entry.getName());
intcount;
bytedata[]=newbyte[BUFFER];
if(entry.isDirectory()){
newFile(destFolder+"/"+entry.getName()).mkdirs();
continue;
}else{
intdi=entry.getName().lastIndexOf('/');
if(di!=-1){
newFile(destFolder+"/"+entry.getName()
.substring(0,di)).mkdirs();
}
}
FileOutputStreamfos=newFileOutputStream(destFolder+"/"
+entry.getName());
dest=newBufferedOutputStream(fos);
while((count=zis.read(data))!=-1)
dest.write(data,0,count);
dest.flush();
dest.close();
}
}rar的只能用第三方api,比如junrar
https://github.com/edmund-wagner/junrar
③ java壓縮中文zip,系統winrar解壓改中文zip會出現亂碼
建議 使用 apache ant 工具包來做壓縮,能完美的解決中文亂碼問題
④ java壓縮zip文件中文亂碼問題
我以前也遇到過這個問題,最後發現java自帶的zip壓縮沒辦法解決中文名亂碼的問題
你可以使用apache ant的zip類(package: org.apache.tools.zip)來解決這個問題。
⑤ 用java直接讀取zip類型的文件時中文亂碼問題怎麼解決
1.一般是軟體程序解碼錯誤。如瀏覽器把GBK碼當成是Big5碼顯示,或電子郵件程序把對方傳來的郵件錯誤解碼。如果在發送時編碼錯誤,收件者的電郵程序是不能解碼的,需要寄件者的電郵程序重新編碼再寄。
2.字體檔案(font file)不對。
3.來源編碼錯誤,或文件受到破壞。
4.一種語言版本的操作系統安裝了另外一種語言版本的應用程序,或者應用程序安裝的升級補丁的語言版本與應用程序原來安裝的語言版本不一致。
5.早期單位元組的應用程序在打開雙位元組語言的文件時不能正確識別文字的分割,在換行的地方把一個字從中分成兩段,導致緊接在後面的整個一行全部都是亂碼。
6.低版本的應用程序不能識別高版本的程序創建的文件。
7.由於TXD等修改文件出現內部沖突,一些修改游戲的MOD(modification)CLEO、IV補丁、真實補丁、技能補丁、升級補丁和CCI人物補丁等游戲修改軟體的「Readme」「必看!」等閱讀文件會出現亂碼。
⑥ java解壓zip文件
不好意思搞反了,這樣就更簡單了。
用這個構造方法ZipInputStream(InputStream in);接收傳過來的流,然後用這個類的getNextEntry()方法解壓縮文件,最後調用read(byte[] b, int off, int len)方法將數據寫入byte數組。
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry = null;
while((entry=zin.getNextEntry())!=null){
if(entry.isDirectory()||entry.getName().equals("..\\"))
continue;
BufferedInputStream bin = new BufferedInputStream(zin);
byte[] buf = new byte[];
bin.read(buf,0,1);
}
⑦ java用apache的ZipEntry壓縮文件名為中文的word文件時,文件名亂碼
apache自帶的zip方法有缺陷,沒有做中文的判斷的,這個是它的一個已知bug。
解決辦法:用jdk的rt.jar裡面的方法實現就可以了。
可以參考下以下工具類:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
*
* @author gdb
*/
public class ZipUtilAll {
public static final int DEFAULT_BUFSIZE = 1024 * 16;
/**
* 解壓Zip文件
*
* @param srcZipFile
* @param destDir
* @throws IOException
*/
public static void unZip(File srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/**
* 解壓Zip文件
*
* @param srcZipFile
* @param destDir
* @throws IOException
*/
public static void unZip(String srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/**
* 解壓Zip文件
*
* @param zipFile
* @param destDir
* @throws IOException
*/
public static void unZip(ZipFile zipFile, String destDir) throws IOException
{
Enumeration<? extends ZipEntry> entryEnum = zipFile.entries();
ZipEntry entry = null;
while (entryEnum.hasMoreElements()) {
entry = entryEnum.nextElement();
File destFile = new File(destDir + entry.getName());
if (entry.isDirectory()) {
destFile.mkdirs();
}
else {
destFile.getParentFile().mkdirs();
InputStream eis = zipFile.getInputStream(entry);
System.out.println(eis.read());
write(eis, destFile);
}
}
}
/**
* 將輸入流中的數據寫到指定文件
*
* @param inputStream
* @param destFile
*/
public static void write(InputStream inputStream, File destFile) throws IOException
{
BufferedInputStream bufIs = null;
BufferedOutputStream bufOs = null;
try {
bufIs = new BufferedInputStream(inputStream);
bufOs = new BufferedOutputStream(new FileOutputStream(destFile));
byte[] buf = new byte[DEFAULT_BUFSIZE];
int len = 0;
while ((len = bufIs.read(buf, 0, buf.length)) > 0) {
bufOs.write(buf, 0, len);
}
} catch (IOException ex) {
throw ex;
} finally {
close(bufOs, bufIs);
}
}
/**
* 安全關閉多個流
*
* @param streams
*/
public static void close(Closeable... streams)
{
try {
for (Closeable s : streams) {
if (s != null)
s.close();
}
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
/**
* @param args
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
// unZip(new File(ZipDemo.class.getResource("D:/123/HKRT-B2B.zip").toURI()), "D:/123/");
unZip("D:/123/123.zip", "D:/123/");
// new File();
}
}
⑧ 如何解決java程序解壓含有中文名的zip壓縮包出現亂碼
上次利用java自動的java.util.zip.ZipEntry和�0�2java.util.zip.ZipFile來解壓zip文件,今天發現程序在讀取解壓文件時居然報了空指針異常,debug程序後發現時讀取不到文件,產生原先是zip壓縮文件中含有中文的名稱,讀取文件名為亂碼,
報找不到文件名,所以報了空指針,想到ant構建文件也有這個功能,換了apache的ant.jar居然解決了中文的問題。
備份下。
�0�2import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;/*** 讀取zip壓縮文件中文本的內容
* @author fish*/public class ReadZip {
public static void main(String args[]) {try {String fileName = "D:/workspace/java/src/ReadZip.zip";
//構造ZipFile
ZipFile zf = new ZipFile(new File(fileName));
//返回 ZIP file entries的枚舉.
Enumeration<? extends ZipEntry entries = zf.getEntries();
while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement();
System.out.println("name:"+ze.getName());
long size = ze.getSize();
if (size 0) {
System.out.println("Length is " + size);
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
⑨ java 解壓zip中文文件保存
用jdk自帶的zip工具做壓縮時,對中文支持不是很好。
建議使用ant.jar中的壓縮和解壓縮工具
⑩ java zip文件解壓
len = zin.read(buff) 不要用 zin,用entry里的
