How to use existing/Predefined table in android?

后端 未结 1 936
忘了有多久
忘了有多久 2021-01-28 00:58

Hi everyone i have one question i.e. i have some database table\'s which are already exist in database but i am not able to use them in my application. I am able to connect to d

1条回答
  •  离开以前
    2021-01-28 01:21

    Answer to my question is simpelly copy your database by using the followig code.

    private void CopyDataBase() throws IOException {

        // open the local database 
            InputStream copy = context.getAssets().open(UR_DB_NAME);
    
        // path where database is created 
        String path_DB = DB_PATH + DB_NAME;
    
        // Open the empty dbOut as the output stream
        OutputStream dbOut = new FileOutputStream(path_DB);
    
        // copy database from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = copy.read(buffer)) > 0) {
            dbOut.write(buffer, 0, length);
        }
    
        // Close the streams
        dbOut.flush();
        dbOut.close();
        copy.close();
    }
    

    0 讨论(0)
提交回复
热议问题