Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The zip function brianestey provided works well, but the unzip function is very slow due to reading one byte at a time. Here is a modified version of his unzip function that utilizes a buffer and is much faster.</p> <pre><code>/** * Unzip a zip file. Will overwrite existing files. * * @param zipFile Full path of the zip file you'd like to unzip. * @param location Full path of the directory you'd like to unzip to (will be created if it doesn't exist). * @throws IOException */ public static void unzip(String zipFile, String location) throws IOException { int size; byte[] buffer = new byte[BUFFER_SIZE]; try { if ( !location.endsWith(File.separator) ) { location += File.separator; } File f = new File(location); if(!f.isDirectory()) { f.mkdirs(); } ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile), BUFFER_SIZE)); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { String path = location + ze.getName(); File unzipFile = new File(path); if (ze.isDirectory()) { if(!unzipFile.isDirectory()) { unzipFile.mkdirs(); } } else { // check for and create parent directories if they don't exist File parentDir = unzipFile.getParentFile(); if ( null != parentDir ) { if ( !parentDir.isDirectory() ) { parentDir.mkdirs(); } } // unzip the file FileOutputStream out = new FileOutputStream(unzipFile, false); BufferedOutputStream fout = new BufferedOutputStream(out, BUFFER_SIZE); try { while ( (size = zin.read(buffer, 0, BUFFER_SIZE)) != -1 ) { fout.write(buffer, 0, size); } zin.closeEntry(); } finally { fout.flush(); fout.close(); } } } } finally { zin.close(); } } catch (Exception e) { Log.e(TAG, "Unzip exception", e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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