贵medDB有任何延期?如果是这样,把它像assetManager.open(“medDB.sqlite”); 您的文件夹结构告诉相同。 所以应该像
AssetManager assetManager = getAssets();
InputStream myInput = assetManager.open("medDB.sqlite");
我在项目中使用此代码:
private void copyFile() {
AssetManager assetManager = mcontext.getAssets();
File f1 = new File(SDCARD_Outer_PATH);
f1.mkdirs();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open("sample.sqlite");
out = new FileOutputStream(SDCARD_DB_PATH);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
结果是一样的。我认为medDB.sqlite可能以某种方式附加到项目中。但我不知道如何 – 2014-09-11 11:24:35
通常,在第一次使用时,我们将资产db复制到SD汽车并从那里使用它。不知道你是如何设计的。此代码适用于我。 – Jithu 2014-09-11 11:26:15
手动复制?我试图用代码来做到这一点,但我需要从资产文件中获取流。我手动将.sqlite数据库放置在assets文件夹中。这是错误的方式? – 2014-09-11 11:28:42