srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.06k stars 310 forks source link

Chinese Character will cause messy code? #455

Open zhangchaojun opened 2 years ago

zhangchaojun commented 2 years ago

can you sovle this problem to make me happy?

srikanth-lingala commented 2 years ago

What exactly is the problem you are facing? You have to be more specific here and provide me with as much info as you could for me to be able to help you.

srikanth-lingala commented 2 years ago

If you are facing any charset issues, try setting charset to GBK when using zip4j like this: zipFile.setCharset(Charset.forName("GBK"));

ChangeStrong commented 2 years ago

二首歌.zip I have this problem.

ZipFile tempFile; try { if (new ZipFile(zipFile.getAbsolutePath()).isEncrypted() == true){ //加密的--尝试一次默认密码 Log.i(TAG, "decompressZip2: 加密的"); isPassword = true; tempFile = new ZipFile(zipFile.getAbsolutePath(), TGFolderModel.passwordForCompressOrDepress.toCharArray()); }else { //未加密--直接解压 Log.i(TAG, "decompressZip2: 未加密的"); tempFile = new ZipFile(zipFile.getAbsolutePath()); } if (tempFile.isValidZipFile() == false){ operateBlock.onOperate(OnOperateBlock.OnOperateBlockStatusFailture,null,"isn't Valid Zip File!",-1); return; } //由于Windows用的gbk编码压缩的文件 macos使用的utf8压缩的--判断压缩文件的编码类型 String charsetStr = getCharset(zipFile); if (charsetStr != null){ Log.i(TAG, "decompressZip2: charset="+charsetStr + " charset2=" + tempFile.getCharset().toString()); //如果探测到编码使用此编码解压 // if (Charset.isSupported(charsetStr)){ // Charset charset1 = Charset.forName(charsetStr);//charsetStr like GBK // tempFile.setCharset(charset1); // }else { // Log.i(TAG, "decompressZip2: 不支持此编码格式"); // } } tempFile.setRunInThread(true); progressMonitor = tempFile.getProgressMonitor(); tempFile.extractAll(fatherFolder.getAbsolutePath()); if I use GBK(like this zipFile.setCharset(Charset.forName("GBK"))) I will get this---> Error occurred. Error message: File header and local file header mismatch。 else I will get messy code. I need you help.

yh-wyz commented 12 months ago

@ChangeStrong 怎么解决的后来

ChangeStrong commented 12 months ago

未解决 换了个库

negier commented 7 months ago

我也遇到了中文乱码问题,但设置zipFile.setCharset(Charset.forName("GBK"));恢复正常,只是这个为什么没有自动识别到呢?