Note that there are some explanatory texts on larger screens.

plurals
  1. POUnzip file in Android
    text
    copied!<p>I got following error when i try to unzip zip file </p> <blockquote> <p>End-of-central-directory signature not found</p> </blockquote> <p>I have also try 7zip lib, it works fine in simple java but in android platform.<br> I get a "dependent jar not found" error.</p> <pre><code>try { // Initiate the ZipFile ZipFile zipFile = new ZipFile(file); String destinationPath = destPath; // If zip file is password protected then set the password if (zipFile.isEncrypted()) { zipFile.setPassword(password); } //Get a list of FileHeader. FileHeader is the header information for all the //files in the ZipFile List fileHeaderList = zipFile.getFileHeaders(); // Loop through all the fileHeaders for (int i = 0; i &lt; fileHeaderList.size(); i++) { FileHeader fileHeader = (FileHeader)fileHeaderList.get(i); if (fileHeader != null) { //Build the output file String outFilePath = destinationPath + System.getProperty("file.separator") + fileHeader.getFileName(); File outFile = new File(outFilePath); //Checks if the file is a directory if (fileHeader.isDirectory()) { //This functionality is up to your requirements //For now I create the directory outFile.mkdirs(); continue; } //Check if the directories(including parent directories) //in the output file path exists File parentDir = outFile.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } //Get the InputStream from the ZipFile is = zipFile.getInputStream(fileHeader); //Initialize the output stream os = new FileOutputStream(outFile); int readLen = -1; byte[] buff = new byte[BUFF_SIZE]; //Loop until End of File and write the contents to the output stream while ((readLen = is.read(buff)) != -1) { os.write(buff, 0, readLen); } //Please have a look into this method for some important comments closeFileHandlers(is, os); //To restore File attributes (ex: last modified file time, //read only flag, etc) of the extracted file, a utility class //can be used as shown below UnzipUtil.applyFileAttributes(fileHeader, outFile); System.out.println("Done extracting: " + fileHeader.getFileName()); } else { System.err.println("fileheader is null. Shouldn't be here"); } </code></pre> <p>//File header always give error</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload