Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot unzip file in android programmatically
    primarykey
    data
    text
    <p>I'm trying to create a mobile dictionary app in android. As a part of the app I'm trying to copy the zipped database file from the assets folder to /data/data/package_name/app_database/file__0/. I'm using the below code to do this. The below code fails to unzip and copy the database to the desired location, but works fine on second time of app launch.</p> <pre><code>public class MainActivity extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { String pName = this.getClass().getPackage().getName(); this.copy("0000000000000001.zip","/data/data/"+pName+"/app_database/file__0/"); } catch (IOException e) { e.printStackTrace(); } super.setIntegerProperty("splashscreen", R.drawable.splash); super.loadUrl("file:///android_asset/www/index.html", 10000); } void copy(String file, String folder) throws IOException { File CheckDirectory; CheckDirectory = new File(folder); if (!CheckDirectory.exists()) { CheckDirectory.mkdir(); } InputStream in = getApplicationContext().getAssets().open(file); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(in)); try { ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { String outputfilename = ze.getName(); OutputStream out = new FileOutputStream(folder+outputfilename); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int count; while ((count = zis.read(buffer)) != -1) { baos.write(buffer, 0, count); byte[] bytes = baos.toByteArray(); out.write(bytes); baos.reset(); } out.flush(); out.close(); } } finally { zis.close(); in.close(); } } </code></pre> <p>}</p> <p>Thanks in advance.</p>
    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.
 

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