How To Access Sqlite Database In The Asset Folder Of An Android Project?
I need help to use use my existing sqlite database in android. i am placing my sqlite database in '/assets/(mydatabase)' but unable to use it. i am using following code. some times
Solution 1:
not sure but this can help you
voidcheckDB() throws Exception {
try {
SQLiteDatabase dbe = SQLiteDatabase
.openDatabase(
"/data/data/yourpackagename/databases/yourfilename.sqlite",
null, 0);
Log.d("opendb", "EXIST");
dbe.close();
} catch (Exception e) {
AssetManager am = getApplicationContext().getAssets();
OutputStream os = new FileOutputStream(
"/data/data/yourpackagename/databases/yourfilename.sqlite");
byte[] b = newbyte[100];
int r;
InputStream is = am.open("yourfilename.sqlite");
while ((r = is.read(b)) != -1) {
os.write(b, 0, r);
}
Log.i("DATABASE_HELPER", "Copying the database ");
is.close();
os.close();
}
}
Solution 2:
Duplication: SQLite Android . unable to open database file
Post a Comment for "How To Access Sqlite Database In The Asset Folder Of An Android Project?"