cocos2d-x 3.0rc2中讀取sqlite文件的方式,在Android中直接讀取軟件內的會失敗。需要複製到可寫的路徑下sql
sqlite3* dbFile = NULL; std::string path; path = FileUtils::getInstance()->fullPathForFilename("db1.db"); #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID path = FileUtils::getInstance()->getWritablePath(); path += "/db1.db"; FILE* file = fopen(path.c_str(), "r"); if (file == nullptr) { ssize_t size; const char* data = (char*) FileUtils::getInstance()->getFileData("db1.db", "rb", &size); file = fopen(path.c_str(), "wb"); fwrite(data, size, 1, file); CC_SAFE_DELETE_ARRAY(data); } fclose(file); #endif CCLOG("數據庫路徑:%s", path.c_str()); int resultOK = sqlite3_open(path.c_str(), &dbFile); if (resultOK != SQLITE_OK) { sqlite3_close(dbFile); CCLOG("數據庫打開失敗: %d", resultOK); return; }