I am doing an app in android, I have .sqlite file in my system which is called 'ff.sqlite'. In the .sqlite file I have 10 tables, very large no of records for tables. In my app(android) I place the .sqlite file in raw folder and I created a database called 'festival.db'. Now I do not know how to import the ff.sqlite file into the festival.db. please help me.
res/raw/ff.sqlite
to create database I use the following code in android:
SQLiteDatabase dbs;
dbs = openOrCreateDatabase("festival.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
My problem is I need all tables in the festival.db from the .sqlite file please help me.
Copy your DB file from assets folder to internal memory, then open DB and do CRUD from there:
private void copyDB() throws IOException{
InputStream myInput = m_Context.getAssets().open(DB-SQLITE_FILE_NAME_KEPT_IN_ASSET_FOLDER);
String outFileName = "/data/data/your.package.name/databases/";
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With