Guest User

Untitled

a guest
Jun 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. private void DBBackup() {
  2. try {
  3. File sd = Environment.getExternalStorageDirectory();
  4. File data = Environment.getDataDirectory();
  5.  
  6. if (sd.canWrite()) {
  7. String currentDBPath = "/data/com.jti.mikee.jti_pos/databases/" + DBHelper.DB_NAME;
  8. String backupDBPath = "DBTRYBACKUP";
  9. File currentDB = new File(data, currentDBPath);
  10. File backupDB = new File(sd, backupDBPath);
  11.  
  12. if (currentDB.exists()) {
  13. FileChannel src = new FileInputStream(currentDB).getChannel();
  14. FileChannel dst = new FileOutputStream(backupDB).getChannel();
  15. dst.transferFrom(src, 0, src.size());
  16. src.close();
  17. dst.close();
  18. }
  19. }
  20. } catch (Throwable e) {
  21. e.printStackTrace();
  22. }
  23. }
  24.  
  25. try {
  26. File sd = android.os.Environment.getExternalStorageDirectory();
  27.  
  28. if (sd.canWrite()) {
  29. File backupDB = new File("/storage/emulated/legacy/DBTRYBACKUP");
  30. File currentDB = new File(getDatabasePath(DBHelper.DB_NAME).getPath());
  31.  
  32. FileChannel src = new FileInputStream(backupDB).getChannel();
  33. FileChannel dst = new FileOutputStream(currentDB).getChannel();
  34. dst.transferFrom(src, 0, src.size());
  35. src.close();
  36. dst.close();
  37. Toast.makeText(getApplicationContext(), "Import Successful!", Toast.LENGTH_SHORT).show();
  38. }
  39. } catch (Throwable e) {
  40. Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT).show();
  41. e.printStackTrace();
  42. }
  43. }
Add Comment
Please, Sign In to add comment