Guest User

Untitled

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. try {
  2. File data = Environment.getDataDirectory();
  3. File sd = new File(Environment.getExternalStorageDirectory() + "/digiplusBackUp");
  4. if (!sd.exists()) {
  5. sd.mkdirs();
  6. }
  7. Calendar c = Calendar.getInstance();
  8. SimpleDateFormat df1 = new SimpleDateFormat("dd-MMM-yyyy");
  9. String formattedDate1 = df1.format(c.getTime());
  10. SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
  11. String formattedDate3 = dateFormat.format(c.getTime());
  12. if (sd.canWrite()) {
  13. String currentDBPath = "/data/com.digiplus.lve/databases/digiplus.db";
  14. String backupDBPath = "backupFolder" + formattedDate1 + formattedDate3;
  15. File currentDB = new File(data, currentDBPath);
  16. File backupDB = new File(sd, backupDBPath);
  17.  
  18. FileChannel src = new FileInputStream(currentDB).getChannel();
  19. FileChannel dst = new FileOutputStream(backupDB).getChannel();
  20. dst.transferFrom(src, 0, src.size());
  21. src.close();
  22. dst.close();
  23. Toast.makeText(getApplicationContext(), "Backup is successful to SD card", Toast.LENGTH_SHORT).show();
  24.  
  25. }
  26. } catch (Exception e) {
  27. Log.d("Error", e.toString());
  28. }
  29.  
  30. }
Add Comment
Please, Sign In to add comment