i have created an sqlite application that contain tables. in that application i have retrieved data from tables. the problem is how can i load that application in android device with my database. 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
将数据库与您的应用程序打包。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.