FileUtils->getInstance()->getFileData was the way for me to go as well for reading asset resources. I wrapped this in a utility function when reading text files:
#include "cocos2d.h"
#include <iosfwd>
#include <sstream>
#include <memory>
namespace FileUtil
{
using ResourceStream = std::basic_istringstream<char>;
bool readResourceFile(std::shared_ptr<ResourceStream>& stream,const std::string& filename);
bool readResourceFile(std::shared_ptr<ResourceStream>& stream,const std::string& filename)
{
// Note: Returned data allocated by "malloc" so must free when copy to string stream
CCLOG("FileUtil::readResourceFile - Attempting to read resource file %s",filename.c_str());
ssize_t size = 0;
char* data = reinterpret_cast<char*>(FileUtils::getInstance()->getFileData(filename, "r", &size));
if(!data || size == 0)
{
CCLOG("FileUtil::readResourceFile - unable to read filename %s - size was %lu",filename.c_str(),size);
if(data)
{
free(data);
}
return false;
}
CCLOG("FileUtil::readResourceFile - Read %lu bytes from resource file %s",size,filename.c_str());
std::string stringData(data);
// release since we've copied to string
free(data);
stream.reset(new std::istringstream(stringData));
return true;
}
}