Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ohh Yes! I have solved it.. :)</p> <p>I have written following function that will create sub-folders recursively if required.</p> <p>This is tried and tested function that will successfully unzips any file.</p> <pre><code> /** * Unzips the file (recursively creates sub-folder if exists.) * * @param tempFileName * The zip file. * @param destinationPath * The destination path where unzipped file will be saved. */ public void unzipFile(String tempFileName, String destinationPath) { try { int index = destinationPath.lastIndexOf("\\"); String fileString = destinationPath.substring(index); File extFile = new File("/mnt/sdcard/courses1", fileString); if(!extFile.exists()) { createDir(extFile); } byte[] buffer = new byte[1024]; FileInputStream fin = new FileInputStream(tempFileName); ZipInputStream zin = new ZipInputStream(fin); ZipEntry zipentry = null; if (!(zin.available() == 0)) { byte[] startBuffer = new byte[8]; while ((zipentry = zin.getNextEntry()) != null) { String zipName = zipentry.getName(); if (zipName.startsWith("/")) { zipName = zipentry.getName(); } else if (zipName.startsWith("\\")) { zipName = zipentry.getName(); } else { zipName = "/" + zipentry.getName(); } String fileName = destinationPath + zipName; fileName = fileName.replace("\\", "/"); fileName = fileName.replace("//", "/"); if (zipentry.isDirectory()) { createDir(new File(fileName)); continue; } String name = zipentry.getName(); int start, end = 0; while (true) { start = name.indexOf('\\', end); end = name.indexOf('\\', start + 1); if (start &gt; 0) "check".toString(); if (end &gt; start &amp;&amp; end &gt; -1 &amp;&amp; start &gt; -1) { String dir = name.substring(1, end); createDir(new File(destinationPath + '/' + dir)); // name = name.substring(end); } else break; } File file = new File(fileName); FileOutputStream tempDexOut = new FileOutputStream(file); int BytesRead = 0; if (zipentry != null) { if (zin != null) { while ((BytesRead = zin.read(buffer)) != -1) { tempDexOut.write(buffer, 0, BytesRead); } tempDexOut.close(); } } } } } catch (Exception e) { Log.e("Exception", e.getMessage()); } } </code></pre> <p>I hope it helps someone. :)</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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