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.live//databases//digiplus";
String backupDBPath = "DigiPlus"+formattedDate1+formattedDate3 ;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
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 ignored) {
Log.d("Error",ignored.tostring());
}
}