Sidebar

How to unzip a file folder which have password security?

0 votes
1.7K views
asked Jul 31, 2018 by (330 points)

i am unzipping a folder using the following code:


var zipFilePath="D:\\readytodelete\\folder\\Test.zip";
var unzipPath="D:\\readytodelete\\folder";
var zipFile = null;

try {
   zipFile = new java.util.zip.ZipFile(zipFilePath);
   var entries = zipFile.entries();
   var bytes = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
   
   while (entries.hasMoreElements()) {
      var zipEntry = new java.util.zip.ZipEntry(entries.nextElement());
      var fileFromZipEntry = new java.io.File(unzipPath + java.io.File.separator + zipEntry.getName());
      
      //zipEntry reports / as separator, even on Windows, so we're not using java.io.File.separator in the following test
      if (StringUtils.endsWith(zipEntry.getName(), '/')) {
         fileFromZipEntry.mkdirs();
         continue;
      } else {
         var inputStream = null;
         var outputStream = null;
         var length = -1;
         
         try {
            inputStream = zipFile.getInputStream(zipEntry);
            outputStream = new java.io.FileOutputStream(fileFromZipEntry);
            
            while ((length = inputStream.read(bytes)) >= 0) {
               outputStream.write(bytes, 0, length);
            }
         } finally {
            if (inputStream !== null) {
               inputStream.close();
               inputStream = null;
            }
            
            if (outputStream !== null) {
               outputStream.close();
               outputStream = null;
            }
         }
      }
   }
} catch (err) {
   qie.error('Failed to unzip file \'' + zipFilePath + '\': ' + err);
} finally {
   if (zipFile !== null) {
      zipFile.close();
      zipFile = null;
   }
}

and this code is working fine now i want to unzip a foder which need passcode before to unzip so what are the required modification i need to do in mapping script? 

please send me the requierd mapping script.

thanx in advance.

1 Answer

+1 vote
It sounds like adding a password to a zip file is not natively available in Java, but could be accomplished using some 3rd party libraries.  https://stackoverflow.com/questions/10587561/password-protected-zip-file-in-java

You can include the jars by adding external libraries: https://www.qvera.com/kb/index.php/256/what-are-external-libraries-or-jar-files
answered Jul 31, 2018 by mike-r-7535 (13,830 points)
commented Aug 1, 2018 by (330 points)
edited Aug 1, 2018 by
yup,, i understand the solution but i didn't add java jar in qie before.as i am new bie for qie,, so please send me end to end solution for that task with snapshots ,,so that i get to know how to add third party jars in qie and how to use that unzip with passcode mapping script,,,,,that is  really very important for our team..your assistance will build our believe in you ,which really metters for us..
thank you v much sir.
commented Aug 2, 2018 by (330 points)
edited Aug 2, 2018 by
dts done thanx a lot..
...