1

I want to get the name of the list of files contained in a .zip file with password using zip4j library version 1.3.2.

package com.gpcoder.compress;
 
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
 
public class UnZip4jExample {
 
    public static final String ZIP_FILE = "C:/demo/zip4jFolderExample.zip";
    public static final String DESTINATION_FOLDER = "C:/demo/outputZip4j";
    public static final String PASSWORD = "yourPassword";
     
    public static void main(String[] args) throws ZipException {
        ZipFile zipFile = new ZipFile(ZIP_FILE);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(PASSWORD);
        }
        zipFile.extractAll(DESTINATION_FOLDER);
        System.out.println("Done!!!");
    }
}
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 2
    Use `getFileHeaders` and call `getFileName` on each `FileHeader` object. (And no, I won't write you an example. You should be able to figure it out from reading the [javadocs](https://javadoc.io/doc/net.lingala.zip4j/zip4j/1.3.2/index.html)!!) – Stephen C May 15 '22 at 07:50

1 Answers1

1

In javafx using zip4j version 1.3.2

You can create a list to save your headers. In list items you can call .getFileName()

        ZipFile zipFile = new ZipFile(fileZip);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        List<FileHeader> fileHeaders = zipFile.getFileHeaders();
        for(FileHeader fileHeader : fileHeaders) {
            System.out.println(fileHeader.getFileName()); // getFileName is ok
            zipFile.extractFile(fileHeader, outputFolder);
        }
quangdang
  • 116
  • 7