cocos2d-x 3.0rc2中读取sqlite文件

cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败。须要复制到可写的路径下

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;
}
上一篇:Java和C#下的参数验证


下一篇:python 基础 ---- 文件读写