Copy sqlite database from apk package to device folder Android example

Put your sglite database to Android Eclipse project folder named Assets.
On device will copy database file to application folder as this example:

 
 public void createDatabase(Context myContext) throws IOException {
    String sPackName = myContext.getPackageName();
    InputStream assetsDB = myContext.getAssets().open("myDatabase");
    OutputStream dbOut = new FileOutputStream("/data/data/"+sPackName+"/database");
 
    byte[] buffer = new byte[1024];
    int length;
    while ((length = assetsDB.read(buffer))>0){
      dbOut.write(buffer, 0, length);
    }
 
    dbOut.flush();
    dbOut.close();
    assetsDB.close();
}
This entry was posted in SQLite database and tagged , , , , , , . Bookmark the permalink.


Comments are closed.



8,980 views