Reputation: 7415
Its all about security. My purpose is to get sqlite file from assets folder & copy it to sd card. It's fine. But now i want to put that sqlite file in one of my package & copy it to sd card.Is it possible?
To copy sqlite file From Assets:
private void copydatabase() throws IOException {
InputStream myinput = mycontext.getAssets().open(DB_ASSETNAME);
OutputStream myoutput = new FileOutputStream(DB_PATH+DB_NAME);
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer))>0) {
myoutput.write(buffer,0,length);
}
myoutput.flush();
myoutput.close();
myinput.close();
}
So how can i copy my sqlite file from package to sdcard?
Structure::
- com.package.packagename
-sqlitefilename.sqlite
Upvotes: 0
Views: 39
Reputation: 1007409
So how can i copy my sqlite file from package to sdcard?
Replace new FileOutputStream(DB_PATH+DB_NAME)
with something that points to external storage (e.g., new FileOutputStream(new File(getExternalFilesDir(), DB_NAME))
). Make sure that you have the WRITE_EXTERNAL_STORAGE
permission, if your minSdkVersion
is set to 18 or lower.
Upvotes: 1