1

I'm trying to decompress a zip file with the API ZipFile from net.lingala.zip4j

public static void unzip(File zipf, File baseDir) throws IOException, ZipException {

    String source = zipf.getAbsolutePath();//"some/compressed/file.zip";
    String destination = baseDir.getPath();//"some/destination/folder";
  //  String password = "password";

    try {
         ZipFile zipFile = new ZipFile(source);
         if (zipFile.isEncrypted()) {
           // zipFile.setPassword(password);
         }
         zipFile.extractAll(destination);
    } catch (ZipException e) {
        e.printStackTrace();
    }
}

I always got the error:

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

May there is other solution to unZip the file.zip correctly?

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
Selma BA
  • 149
  • 3
  • 18
  • 1
    http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/ – Raphael Roth Jun 01 '16 at 09:37
  • Try Apache Commons Compression. Besides that you provide really little information. Maybe the exception is right and your file is not a valid zip. – Thomas Jun 01 '16 at 09:41

1 Answers1

0

Your code is perfect. I have run your code on my system, it works superbly. I have used zip4j-1.3.1.jar from http://central.maven.org/maven2/net/lingala/zip4j/zip4j/1.3.1/zip4j-1.3.1.jar. Please run it again with a different zip file. Your zip file may be a corrupted one.

Sanjeev Saha
  • 2,632
  • 1
  • 12
  • 19