[英]how can i store database in android device?
i have created an sqlite application that contain tables. 我创建了一个包含表的sqlite应用程序。 in that application i have retrieved data from tables.
在那个应用程序中,我已经从表中检索了数据。 the problem is how can i load that application in android device with my database.
问题是如何将数据库中的应用程序加载到android设备中。 i have tried but i didn't found answer.
我已经尝试过,但是没有找到答案。 in my application i have used the below code.
在我的应用程序中,我使用了以下代码。
try{
String destpath = "/data/data/"+getPackageName()+"/database/mmts1.db";
File f = new File(destpath);
if(!f.exists())
{
copyDb(getResources().getAssets().open("mmts1.db"),new FileOutputStream(destpath));
}
}
catch(FileNotFoundException e)
{
Log.e("FileNotFoundException",e.getMessage());
}
catch(IOException e)
{
Log.e("IoException",e.getMessage());
}
private void copyDb(InputStream open, FileOutputStream fileOutputStream) throws IOException{
// TODO Auto-generated method stub
byte [] buffer = new byte[1024];
int length;
while((length=open.read(buffer))>0)
{
fileOutputStream.write(buffer,0,length);
}
open.close();
fileOutputStream.close();
}
使用SQLiteAssetHelper
将数据库与您的应用程序打包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.