通常,要更改数据库,我遵循以下步骤:
-
-
删除“我的资产”文件夹中的数据库
-
再次复制资产文件夹中的粘贴数据库
-
-
重建/安装应用程序
我通过从我的资产文件夹中删除数据库并重新安装应用程序来解决这个问题。据我所知,该应用程序仍然可以工作,因此它无法从我以前使用的资产文件夹访问数据库。
我正在使用以下路径访问它:
DB_Path = mContext.getDatabasePath(DB_Name).
Log.e("DB_path", DB_Path);
会产生
.com.example.chris.projectartifact E/DB_path:/data/user/0/com.example.chris.projectartifact/databases/myDB.db
关于评论:
我正在使用以下方法复制我的数据库。
这是从一个教程,它很好的工作了很长一段时间。
但据我所知
FileOutputStream(DB_Path)
将其复制到命名路径。
public void copyDataBase(){
try {
InputStream myInput = mContext.getAssets().open(DB_Name);
OutputStream myOutput = new FileOutputStream(DB_Path);
byte[] buffer = new byte[1024];
int length;
while ((length=myInput.read(buffer))>0){
myOutput.write(buffer,0,length);
}
myOutput.flush();
myOutput.close();
myInput.close();
} catch (IOException e){
Log.e("Error:","in CopyDatabase, where are in catch..");
e.printStackTrace();
}
}
问题是:
-
我在哪里可以找到我的数据库?
-
我如何才能更新它?
-
新问题:
如何删除复制的数据库并从资产文件夹中续订?