net.lingala.zip4j.exception.ZipException: Zip headers not found. Probably not a zip file or a corrupted zip file

See original GitHub issue

What’s the problem?

public static void zipFileWithPassword(List<String> fileList, String zipFileName, String password) {
        try {
            //files
            ArrayList<File> files = new ArrayList<>();
            for (String oneFile : fileList){
                File file = new File(oneFile);
                files.add(file);
            }
            ZipParameters zipParameters = new ZipParameters();
            zipParameters.setEncryptFiles(true);
            zipParameters.setEncryptionMethod(EncryptionMethod.AES);
            zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
            ZipFile zipFile = new ZipFile(zipFileName, password.toCharArray());
            zipFile.addFiles(files, zipParameters);
        } catch (ZipException e) {
            e.printStackTrace();
        }
    }

zipFileName

String filename = "/tmp/souquan-net.zip";
File file = new File(filename);
            if (!file.exists()) {
                boolean status = file.createNewFile();
                if (!status) {
                    logger.error("Create zip file error");
                }
            }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
srikanth-lingalacommented, Nov 26, 2019

To me the problem looks like you are creating a new file if the file does not exist file.createNewFile(). This will just create an empty file, which is not a valid zip file. You don’t have to create an empty file before calling any of zip4j’s addFiles methods

1reaction
srikanth-lingalacommented, Nov 26, 2019

If you get this exception:

net.lingala.zip4j.exception.ZipException: Zip headers not found. Probably not a zip file or a corrupted zip file

when you are adding files to a zip, it usually means that a zip file already exists at the specified location, which in your case is /tmp/souquan-net.zip and that this zip file is corrupt, and not a valid zip file. When adding files to a zip, zip4j will first check if the zip file already exists. If the file exists, it will try to read the zip headers to add files to the existing zip file. At this step, if the zip file is corrupt, then zip4j will throw the exception you get. If you are adding files to an existing zip file, this zip file has to be a valid zip file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

zip headers not found. probably not a zip file - Stack Overflow
zip.zip, and cannot find 000033541066253_D.zip.ZIP, period. I use zip4j zip lib. Kindly help to fix this problem.
Read more >
net.lingala.zip4j.exception.ZipException when unco...
I have been using Project Configurator for Jira to move a project from one server to another. But it is always showing the...
Read more >
Java Examples for net.lingala.zip4j.exception ... - Javatips.net
ENDSIG)) { throw new ZipException("zip headers not found. probably not a zip file"); } byte[] intBuff = new byte[4]; byte[] shortBuff = new...
Read more >
net.lingala.zip4j.headers.HeaderReader Maven / Gradle / Ivy
The class is part of the package ➦ Group: net.lingala.zip4j ➦ Artifact: zip4j ➦ Version: 2.3.2. ... Zip4j - A Java library for...
Read more >
Unzip under Linux | B4X Programming Forum
Hi, All What ZIP lib better for Linux ? To unzip whole folder\subfolders. ... Zip headers not found, probably not a zip file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found