0
我想將我的數據庫文件存儲在可繪製的文件夾中,然後在SD卡中創建其備份。雖然試圖做到這一點我findind問題在什麼路徑給予可繪製的文件夾。我這樣做:數據庫存儲和檢索
嘗試{
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
//db = openOrCreateDatabase("demodatabase.sqlite",SQLiteDatabase.CREATE_IF_NECESSARY,null);
currentDBPath = "//drawable//demodatabase.sqlite";
db=openOrCreateDatabase(uri.toString(), 0, null);
System.out.println("====="+ currentDBPath);
backupDBPath = "{demodatabase.sqlite}";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, 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();
}
} }catch (Exception e) {}
Thanx提前。
我得到空指針異常得到一個輸入流對這些文件的情況下沒有采取值...爲什麼如此?] – Piyush 2011-04-13 12:44:42
您是否使用SQLiteOpenHelper類作爲超類? – senola 2011-04-13 12:58:43
不,我只是擴展活動..... – Piyush 2011-04-13 13:04:59