我想创建一个我的数据库的备份,但我手机上没有SDCARD.我想在内部存储中创建备份,但下一个代码失败...
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//storage//sdcard0//MyApp//turnos.db";
String backupDBPath = "turnos.db";
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();
}
} mensajeOK("INFO", "Copia creada.");
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
我有权限WRITE_EXTERNAL_STORAGE.