在我的项目中,我已经使用此工具导入了一个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 File Explorer中删除数据库文件并尝试再次导入它时,代码崩溃了。
它说找不到这样的文件并创建一个空数据库...有什么办法可以解决这个问题?
您必须先删除以前的数据库,然后才能再次导入它。用这个Context.deleteDatabase("DB_NAME")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句