Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void checkDataBase() {
- SQLiteDatabase checkDB = null;
- try {
- checkDB = SQLiteDatabase.openDatabase(getApplicationContext().getDatabasePath(DB_NAME).getPath(), null, SQLiteDatabase.OPEN_READONLY);
- } catch (SQLiteException e) {
- e.printStackTrace();
- }
- if (checkDB != null) {
- checkDB.close();
- } else {
- try {
- copyDataBase();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private void copyDataBase() throws IOException {
- InputStream myInput = getApplicationContext().getAssets().open(DB_NAME);
- OutputStream myOutput = new FileOutputStream(getApplicationContext().getDatabasePath(DB_NAME).getPath());
- byte[] buffer = new byte[1024];
- int length;
- while ((length = myInput.read(buffer)) > 0) {
- myOutput.write(buffer, 0, length);
- }
- myOutput.flush();
- myOutput.close();
- myInput.close();
- }
Add Comment
Please, Sign In to add comment