Copying our Database from /assets to data/data/databases

Often we come across situation where we need to copy a database over an existing database(Usually Empty). Here is a sample code to copy our database from the Application’s assets folder over an empty DB for use

void copyDatabase() throws IOException{
InputStream myInput = myContext.getAssets().open(DBNAME);
OutputStream myOutput = new FileOutputStream(DBPATH+DBNAME);
byte[ ] buffer = new byte[1024];
int length;
while ((length =>0){
myOutput.write(buffer, 0, length);

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>