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);