我在 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/