Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy two SQLite Database in asset folder in Android

For the last few days I've been trying to copy two databases in the asset folder, but could not get any success.

One database I managed to copy and access it. But the second one, I need your help.

like image 579
Strider Avatar asked Oct 08 '22 23:10

Strider


1 Answers

private void copydatabase() throws IOException {
//Open your local db as the input stream
InputStream myinput = mycontext.getAssets().open(DB_NAME);// Path to the just created empty db
String outfilename = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myoutput = new FileOutputStream("/data/data/(packagename)/databases   /(datbasename).sqlite");
// transfer byte to inputfile to outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer))>0)
{
myoutput.write(buffer,0,length);
}
//Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
}

Do this for your second database.

like image 164
Dhruvisha Avatar answered Oct 13 '22 12:10

Dhruvisha