小编lok*_*usu的帖子

创建没有SD卡的备份数据库

我想创建一个我的数据库的备份,但我手机上没有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.

database backup android

1
推荐指数
1
解决办法
337
查看次数

标签 统计

android ×1

backup ×1

database ×1