net.lingala.zip4j.exception.ZipException: Zip headers not found. Probably not a zip file or a corrupted zip file
See original GitHub issueWhat’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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 methodsIf you get this exception:
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.zipand 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.