I want to use zip4j on Android to expand zip file with password, but it causes garbled characters.

Asked 2 years ago, Updated 2 years ago, 40 views

I am creating an application to deploy zip files with passwords on Android, but when I unzip a zip file containing a Japanese name, the file containing Japanese is garbled.

Please let me know if there are any hints on how to unzip without garbled characters.

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.UnzipParameters;


public class MainActivity extensions FragmentActivity{

    @ Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView (R.layout.main);

        try{
            String zipFilePath=Environment.getExternalStorageDirectory().getPath()+"/PassZip/Japanese.zip";
            String destinationPath=Environment.getExternalStorageDirectory().getPath()+"/PassZip/";
            File dir=new File(Environment.getExternalStorageDirectory().getPath()+"/PassZip/");
            if(!dir.exists()){
                dir.mkdir();
            }
            String password = "password";
            try{
                ZipFile zipFile = new ZipFile(zipFilePath);
                if(zipFile.isEncrypted()){
                    zipFile.setFileNameCharset("csWindows31J")
                    zipFile.setPassword(password);
                }
                zipFile.extractAll(destinationPath);
            } catch(ZipExceptione){
                e.printStackTrace();
            }

        }catch(Exceptione){}
    }
}

java android

2022-09-30 20:23

1 Answers

Previously, I created a library (airxzip) to extract Zip files in ActionScript.

First, the Zip file name is UTF-8 or Windows-31J (SJIS).
If I remember correctly, there was no exact specification for the character code of the file name.

Also, UTF-8 is troublesome, and Windows and MAC think differently about turbidity, so if you don't control this hit, you'll have to write it down.
(That's why Japanese is often garbled in MAC.)

This is not Java, but the following getFilenameUTF8 method is decoding UTF-8.

https://github.com/coltware/airxzip/blob/master/airxzip/src/com/coltware/airxzip/ZipHeader.as

I think it's okay because there were no cases where this caused problems.


2022-09-30 20:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.