Guest User

Untitled

a guest
May 1st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. private void checkDataBase() {
  2. SQLiteDatabase checkDB = null;
  3. try {
  4. checkDB = SQLiteDatabase.openDatabase(getApplicationContext().getDatabasePath(DB_NAME).getPath(), null, SQLiteDatabase.OPEN_READONLY);
  5. } catch (SQLiteException e) {
  6. e.printStackTrace();
  7. }
  8.  
  9. if (checkDB != null) {
  10. checkDB.close();
  11. } else {
  12. try {
  13. copyDataBase();
  14. } catch (IOException e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. }
  19.  
  20. private void copyDataBase() throws IOException {
  21. InputStream myInput = getApplicationContext().getAssets().open(DB_NAME);
  22. OutputStream myOutput = new FileOutputStream(getApplicationContext().getDatabasePath(DB_NAME).getPath());
  23. byte[] buffer = new byte[1024];
  24. int length;
  25. while ((length = myInput.read(buffer)) > 0) {
  26. myOutput.write(buffer, 0, length);
  27. }
  28. myOutput.flush();
  29. myOutput.close();
  30. myInput.close();
  31. }
Add Comment
Please, Sign In to add comment