-2
我想從我的應用程序中導出SQLite數據庫,以便我可以爲我的應用程序執行導出/導入功能。Android導出SQLite數據庫
我使用從here & here企圖出口SQLite數據庫(/data/data/com.example.worldcountriesbooks/databases/group.db)了Android設備的例子(三星Galaxy Note) ,安卓4.0.3但我不斷收到此錯誤
12-14 00:56:33.722: I/Failed(14850): java.io.FileNotFoundException: /data/data/com.example.worldcountriesbooks/databases/group.db: open failed: ENOENT (No such file or directory)
我也試圖給WRITE_EXTERNAL_STORAGE
& WRITE_MEDIA_STORAGE
添加到清單文件,但它不工作。我能夠瀏覽到我的Android設備上的實際文件,因爲它是根植的,但我無法用我的應用程序讀取它。任何想法爲什麼?
示例代碼:
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//com.example.worldcountriesbooks/databases//group.db";
String backupDBPath = "//mnt//sdcard//database.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getBaseContext(), backupDB.toString(),
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
.show();
}
所以沒有辦法,我可以從我的應用程序複製了SQLite數據庫? – dythe
寫在SD卡上 – thaussma
是的,我已經試圖寫它到我的SD卡,但它甚至不能打開'/數據/數據'內部數據庫寫入SD卡 – dythe