【问题标题】:Andorid Room database how to export the dbAndroid Room数据库如何导出db
【发布时间】:2020-08-13 20:40:35
【问题描述】:

由于我已经从下面的代码中导出了数据库文件,但我无法打开导出的文件,我该如何打开导出的文件?

 String dbName = Constants.DATABASE_NAME ; // Name without .db
 String currentDBPath = context.getDatabasePath(dbName).getPath();

 String backupDBPath = MyHelper.getDbExportPath() + "/" + dbName;
 File currentDB = new File(currentDBPath);
 File backupDB = new File(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();
}

【问题讨论】:

标签: android android-room


【解决方案1】:

对于 currentDBPath,不要考虑 .db 扩展名,但对于 backupDBPath,它需要一个 .db 扩展名

String backupDBPath = MyHelper.getDbExportPath() + "/" + dbName + ".db";

解决问题

【讨论】:

    猜你喜欢
    • 2018-10-26
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多