SQLite数据库导出

时间:2016-08-19 07:43:12

标签: android sqlite android-sqlite backup android-6.0-marshmallow

我正在尝试制作简单的应用。在那里我想存储数据库并将其导出到存储中进行备份。我的代码在Android kitkat和棒棒糖上正常工作,但没有在Android marshmallow中进行任何数据库备份

public void copyAppDbToDownloadFolder(Context context) throws IOException {

    File backupDB = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "BackUpFolder.db"); // for example "my_data_backup.db"
    File currentDB = context.getDatabasePath("expense.db"); //databaseName=your current application database name, for example "my_data.db"
    if (currentDB.exists()) {
        Log.d("d", "copyAppDbToDownloadFolder--->>if condition<<<---");
        FileChannel src = new FileInputStream(currentDB).getChannel();
        FileChannel dst = new FileOutputStream(backupDB).getChannel();

        dst.transferFrom(src, 0, src.size());
        Log.d("s", "transform");
        src.close();
        dst.close();
    }
}

我用这种方法进行导出。我试图在棉花糖中找到问题,但我不能。有人可以帮忙吗?

0 个答案:

没有答案