我需要对移动设备的内部存储或SD卡中的SQLite数据库进行离线备份。但我一无所知,这有可能吗。
我在SO上跟随了很多主题,但它们建议将DB从一个位置复制到另一个位置,这对我来说不合适,也不适用于Google Drive。
任何指导都是宝贵的。
我需要对移动设备的内部存储或SD卡中的SQLite数据库进行离线备份。但我一无所知,这有可能吗。
我在SO上跟随了很多主题,但它们建议将DB从一个位置复制到另一个位置,这对我来说不合适,也不适用于Google Drive。
任何指导都是宝贵的。
public string DATABASE_NAME = "YOUR DATABASE NAME HERE";
public void exportDB(){
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
Log.d("TAG", "DatabaseHandler: can write in sd");
//Replace with YOUR_PACKAGE_NAME and YOUR_DB_NAME
String currentDBPath = "filepath here"+DATABASE_NAME;
//Replace with YOUR_FOLDER_PATH and TARGET_DB_NAME in the SD card
String copieDBPath = DATABASE_NAME;
File currentDB = new File(data, currentDBPath);
File copieDB = new File(sd, copieDBPath);
if (currentDB.exists()) {
Log.d("TAG", "DatabaseHandler: DB exist");
@SuppressWarnings("resource")
FileChannel src = new FileInputStream(currentDB).getChannel();
@SuppressWarnings("resource")
FileChannel dst = new FileOutputStream(copieDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Google Drive
备份,因为我不需要。 - Mohammedsalim Shivani