这段代码解决了我的问题,谢谢 MikeT 的支持
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());
}
}
现在我想恢复备份,我该怎么做?