How to update FileUtils?

I am using the following code to read a string from a file:

auto levelData = FileUtils::getInstance()->getFileData(fileName, "r", &fileSize);

Then I make a change to the data and save it over the same file using the following code:

std::ofstream file(fileName);
file << strbuf.GetString();
file.close();

I know the saving process worked because I observe that the new data is present in the file now. However when I try to read the file again, I get the old version of the file instead of the new one. When I close the program and run it again, I finally get the new updated data. I’m guessing that FileUtils is caching my old data instead of reading the file like it does the first time I call it. Is there any way to prevent this or maybe clear the cache? I’ve already tried calling FileUtils::destroyInstance() and FileUtils->getInstance()->purgeCachesEntries(), but I’ve had no luck. Any ideas?

Hi, hotcoco. In CCFileUtils.cpp, FileUtils use getContents function to get data.
FileUtils::getContents have a code std::string fullPath = fs->fullPathForFilename(filename);
=> When you use std::ofstream file(fileName), maybe it not open the same file with FileUtils open.
You could use this code:
string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::ofstream file(fullPath );
file << strbuf.GetString();
file.close();

(Sorry for the English I was not good :slight_smile: )