Android 从 Assets 复制 SQLite 数据库在 KitKat 4.4 上不起作用

标签 android sqlite android-4.4-kitkat

我在 StackOverflow 上提出了不同的问题,但我的问题有点新。

所有这些都不起作用: Question1 Question2 Question3

我将我的设备更新到 Android KitKat 4.4,当我尝试使用此代码复制数据库时:

private void copyDataBase() throws IOException {
    InputStream myInput = context.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();
}

我在以下行获得 FileNotFoundException:

OutputStream myOutput = new FileOutputStream(outFileName);

有人在 Android KitKat 上解决了这个问题??? (其他平台效果很好)

感谢您的帮助。

朱利奥

最佳答案

Full hardcoded

永远不要硬编码路径Use getDatabasePath()为数据库找到合适的位置。

other platforms works great

对于辅助帐户,它肯定会在 Android 4.2+ 平板电脑上崩溃。它也可能在其他环境中崩溃。 永远不要对路径进行硬编码

请注意 SQLiteAssetHelper使用 getDatabasePath()

关于Android 从 Assets 复制 SQLite 数据库在 KitKat 4.4 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20070709/

相关文章:

android - 如何在线性布局中添加 ScrollView

android - Android 中的谷歌地图聚类

java - 在 Java 中扩展父类(super class)时用点表示

android - Android Kitkat (4.4) 的来电显示功能的新功能是否有 API?

java - 单个应用程序的多种产品风格

android - SQLite 查询字符串

php - SQLite通过php将数据持久保存到MySQL服务器iOS

iphone - 随着表变大,Sqlite3 插入到非索引表需要更长的时间

android - 无法访问辅助存储(外部可移动微型 SD 卡)

android - Kamailio 和安卓 SIP