3

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.

1 Answer 1

6

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

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.