[英]Andorid Room database how to export the db
由於我已經從下面的代碼中導出了數據庫文件,但我無法打開導出的文件,我該如何打開導出的文件?
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();
}
對於 currentDBPath 不考慮 .db 擴展,但對於 backupDBPath 它需要 a.db 擴展
String backupDBPath = MyHelper.getDbExportPath() + "/" + dbName + ".db";
解決這個問題
下載並安裝 SQLite 的數據庫瀏覽器
在 Android Studio 版本 >= 3.0 中:
通過以下方式打開設備文件資源管理器:
查看 > 工具 Windows > 設備文件資源管理器
在“設備文件資源管理器”Go 中:
數據 > 數據 > PACKAGE_NAME > 數據庫
其中 PACKAGE_NAME 是您的 package 的名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.