Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- File data = Environment.getDataDirectory();
- File sd = new File(Environment.getExternalStorageDirectory() + "/digiplusBackUp");
- if (!sd.exists()) {
- sd.mkdirs();
- }
- Calendar c = Calendar.getInstance();
- SimpleDateFormat df1 = new SimpleDateFormat("dd-MMM-yyyy");
- String formattedDate1 = df1.format(c.getTime());
- SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
- String formattedDate3 = dateFormat.format(c.getTime());
- if (sd.canWrite()) {
- String currentDBPath = "/data/com.digiplus.lve/databases/digiplus.db";
- String backupDBPath = "backupFolder" + formattedDate1 + formattedDate3;
- File currentDB = new File(data, currentDBPath);
- File backupDB = new File(sd, backupDBPath);
- FileChannel src = new FileInputStream(currentDB).getChannel();
- FileChannel dst = new FileOutputStream(backupDB).getChannel();
- dst.transferFrom(src, 0, src.size());
- src.close();
- dst.close();
- Toast.makeText(getApplicationContext(), "Backup is successful to SD card", Toast.LENGTH_SHORT).show();
- }
- } catch (Exception e) {
- Log.d("Error", e.toString());
- }
- }
Add Comment
Please, Sign In to add comment