Search code examples
androidsqliteandroid-sqlitesqliteopenhelper

Android SQLite database re-Import


in my project i have imported a sqlite database using this..

private void copyDataBase() throws IOException{

    InputStream myInput = myContext.getAssets().open(DB_NAME);

    String outFileName = DB_PATH + DB_NAME;

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

}

It Works fine. But When I delete the database file from the DDMS File Explorer and try to import it again, the code breaks down.

it says no such file found and create a empty database... Is there any way to overcome this problem?


Solution

  • You Have to delete the previous database before import it again. use this Context.deleteDatabase("DB_NAME")