Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import .sqlite into database in sqlite on android

Tags:

android

sqlite

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.

like image 943
M.A.Murali Avatar asked Dec 13 '25 00:12

M.A.Murali


1 Answers

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

    }
like image 165
Vinayak Bevinakatti Avatar answered Dec 14 '25 15:12

Vinayak Bevinakatti