【问题标题】:Android SQLite database re-ImportAndroid SQLite 数据库重新导入
【发布时间】:2014-08-17 06:21:42
【问题描述】:

在我的项目中,我使用这个导入了一个 sqlite 数据库..

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

}

它工作正常。但是当我从 DDMS 文件资源管理器中删除数据库文件并尝试再次导入时,代码会崩溃。

它说没有找到这样的文件并创建一个空数据库... 有没有办法克服这个问题?

【问题讨论】:

  • use SQLiteAssetHelper 使用应用程序打包数据库。
  • 其实我不知道如何使用SQLiteAssetHelper。你能给我一个教程之类的吗? @CommonsWare
  • @AnwarHossain 这就是链接的用途。学习。

标签: android sqlite android-sqlite sqliteopenhelper


【解决方案1】:

您必须在再次导入之前删除以前的数据库。 使用这个Context.deleteDatabase("DB_NAME")

【讨论】:

    猜你喜欢
    • 2013-05-08
    • 1970-01-01
    • 2021-10-06
    • 2018-08-26
    • 2016-03-04
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多