3
 for(int i=0; i<password.length;i++){
      ZipFile zip = new ZipFile(path);
      if (zip.isEncrypted()) {
          zip.setPassword(password[i]);
      }
      try{
          zip.extractAll(neweachpath);
      } 
      catch(ZipException e)
      {if (e.getCode()==ZipExceptionConstants.WRONG_PASSWORD){
          //System.out.println("wrong password");
      }
  }
  }

I use this piece of code to unzip file with password. The problem is if the zip file has many subfiles, the first one unzipped is empty,others are fine. If the zip file has one subfile, then the result is empty. Anyone knows how this happened? thanks.

ps. the iteration is just a way to try the password out

printemp
  • 869
  • 1
  • 10
  • 33
  • You appear to be trying to extract the same zip file on each iteration - that seems very odd to me. – Jon Skeet Jul 28 '15 at 09:14
  • "ps. the iteration is just a way to try the password out" - that sounds like you should be looping *inside `if (zip.isEncrypted())` then, and catching the exception there too. – Jon Skeet Jul 28 '15 at 09:25
  • @printemp have you tried to using JD decompiler to figure out what happend within the library? – Reporter Jul 28 '15 at 09:27

0 Answers0