Where To Save Read-only *.db File In Android Project?
Sorry for trivial question, I've a .db sqlite3 file that I'm suppose to take data, e.g. it's read-only. But I'm wondering where to import it, while taking the path of this data fil
Solution 1:
import it following path
"/data/data/ur_package_name/databases/"
Solution 2:
In my project I have a folder under the project called assets, I put my *.db there and load the database like this:
privatestaticvoidcopyDatabase(String dbname) throws IOException {
InputStream is = mContext.getAssets().open(dbname);
String outFileName = DB_PATH + dbname;
OutputStream out = new FileOutputStream(outFileName);
byte[] buffer = newbyte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
is.close();
out.flush();
out.close();
}
Post a Comment for "Where To Save Read-only *.db File In Android Project?"