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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.