Android 的apk在覆盖安装的时如何重新读取raw或assets目录下的sqlite数据库

sosohotsummer 2013-04-12 05:04:28

Android 的新版本的apk在覆盖安装的时如何重新读取raw或assets目录下的sqlite数据库,在新版中可能修改了sqlite数据库中的某些表,增加或删除了某些字段,因此需要在DBOpenHelper类中修改数据库版本VERSION和onUpgrade方法,先删除掉原来的表,再重新执行onCreate方法中的建表语句,然后再将sqlite数据库中的数据读入到"/data/data/" + context.getPackageName() +"/databases";中,为什么读入的所有数据都为空?
关键代码如下:
CopyDB(ac.getBaseContext().getAssets().open("db1"),new FileOutputStream(destPath + "/db1.db"));//读入assets目录下的db1数据库
public void CopyDB(InputStream inputStream, OutputStream outputStream) throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
...全文
347 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
century_huang 2015-05-11
  • 打赏
  • 举报
回复
粗暴解决,解析已存在数据库,插入现在数据库
码仔2020 2013-07-26
  • 打赏
  • 举报
回复
我也遇到这种需求,不知道楼主怎么解决的,分享一下。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧