[英]Access or open database from external storage in android
->好的,這里我在SD卡中有一個Sq-lite數據庫。
(String DB_PATH = Environment.getExternalStorageDirectory().getPath().toString();)
->檢查數據庫是否存在
dbFile = new File(DB_PATH + DB_NAME );
if(dbFile.exists()== true)
{
//set text db exists
open_DB();
}
else
{
//set text db does not exist
return;
}
->在調試時,我可以確認數據庫文件的存在。 但是當打開
我得到的數據庫異常
SQLiteDatabase checkDB = null;
try
{
dbFile = new File(DB_PATH + DB_NAME);
myDataBase = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
//myDataBase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, 0);
//also tried this
//set text bd opened
}
catch(SQLiteException e)
{
//set text bd unable open
return;
}
可能是您的問題是由標志或文件引起的,請嘗試使用此方法:
dbFile = new File(DB_PATH + DB_NAME);
if (dbFile.exists()) {
db = SQLiteDatabase.openDatabase(db_path, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);
}
讓我知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.