我想共享一个方法来检查数据库是否存在:
如果它适合你,给我一个+1,
谢谢。
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
File database=myContext.getDatabasePath(DB_NAME);
if (database.exists()) {
Log.i("Database", "Found");
String myPath = database.getAbsolutePath();
Log.i("Database Path", myPath);
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} else {
// Database does not exist so copy it from assets here
Log.i("Database", "Not Found");
}
} catch(SQLiteException e) {
Log.i("Database", "Not Found");
} finally {
if(checkDB != null) {
checkDB.close();
}
}
return checkDB != null ? true : false;
}