// copy the game database into the writable path (document directory)
string dbFilePath = CCFileUtils::sharedFileUtils()->fullPathForFilename(GAME_DB_NAME);
string writablePath = createDownLoadUrl() + GAME_DB_NAME;
unsigned long dbSize;
CCFileUtils::sharedFileUtils()->getFileData(writablePath.c_str(), "r", &dbSize);
if(!dbSize){
std::fstream fsCopee( dbFilePath.c_str(), ios::binary | ios::in ) ;
std::fstream fsCoper( writablePath.c_str(), ios::binary | ios::out ) ;
fsCoper << fsCopee.rdbuf();
}
```
string AppDelegate::createDownLoadUrl(){
string pathToSave;
pathToSave = CCFileUtils::sharedFileUtils()->getWritablePath();
pathToSave += DOWNLOAD_PATH;
// Create the folder if it doesn't exist
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
DIR *pDir = NULL;
pDir = opendir (pathToSave.c_str());
if (!pDir)
{
mkdir(pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
}
#else
if ((GetFileAttributesA(pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES)
{
CreateDirectoryA(pathToSave.c_str(), 0);
}
#endif
return pathToSave;
}
```
这是我用来拷贝数据库的一段代码。