zip4j icon indicating copy to clipboard operation
zip4j copied to clipboard

Chinese Character will cause messy code?

Open zhangchaojun opened this issue 3 years ago • 6 comments

can you sovle this problem to make me happy?

zhangchaojun avatar Jul 25 '22 13:07 zhangchaojun

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 avatar Jul 26 '22 15:07 srikanth-lingala

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

srikanth-lingala avatar Jul 26 '22 15:07 srikanth-lingala

二首歌.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.

ChangeStrong avatar Aug 10 '22 09:08 ChangeStrong