我已成功備份了我的數據庫,但問題是我的備份保存在SD卡中的內部存儲器中。如何在SD卡中進行數據庫備份
這裏是我的代碼:
public void exportDatabase()
{
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
String currentDBPath = "/data/" + "com.arpanexample.spm" + "/databases/" + Database.DATABASE_NAME;
String backupDBPath = Database.DATABASE_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
FileChannel source = new FileInputStream(currentDB).getChannel();
FileChannel destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(context, "Successfully backup your data", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}