且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android中使用现有的/ predefined表?

更新时间:2022-06-26 07:49:39

回答我的问题是通过使用followig code simpelly复制数据库。

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

私人无效CopyDataBase()抛出IOException异常{

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