我使用SQL數據庫在我appliaction,在我想拿database.I的備份有以下疑點:數據庫備份的Android
1.I正在運行的仿真器的應用,用於檢測是否我必須插入一些外部存儲器來檢查,如果不在我的系統中,我該如何檢查。 2.我在我的應用程序中使用了下面的代碼,因爲sdcard.write選項顯示爲false,這是什麼錯誤。
Follwing是我的代碼:
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
java.lang.System.out.println("data="+sd.getAbsolutePath());
java.lang.System.out.println("data="+sd.canWrite());--->Showing as false
if (sd.canWrite()) {
String currentDBPath = "\\data\\com.budget\\databases\\budget";
String backupDBPath = "budget";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
java.lang.System.out.println("backup="+backupDB.getAbsolutePath());
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();
}
}
} catch (Exception e) {
}
感謝Harald ..但在我的情況下,if(sd.canWrite()) - >本身顯示爲false,因此它不會進入該if循環。 – subbu