string getFileByName(string pFileName){
//第一先获取文件的路径
string path = CCFileUtils::sharedFileUtils()->getWriteablePath() + pFileName;
CCLOG("path = %s",path.c_str());
//创建一个文件指针
FILE* file = fopen(path.c_str(), "r");
if (file) {
char* buf; //要获取的字符串
int len; //获取的长度
/*获取长度*/
fseek(file, 0, SEEK_END); //移到尾部
len = ftell(file); //提取长度
rewind(file); //回归原位
CCLOG("count the file content len = %d",len);
//分配buf空间
buf = (char*)malloc(sizeof(char) * len + 1);
if (!buf) {
CCLOG("malloc space is not enough.");
return NULL;
}
//第一先获取文件的路径
string path = CCFileUtils::sharedFileUtils()->getWriteablePath() + pFileName;
CCLOG("path = %s",path.c_str());
//创建一个文件指针
FILE* file = fopen(path.c_str(), "r");
if (file) {
char* buf; //要获取的字符串
int len; //获取的长度
/*获取长度*/
fseek(file, 0, SEEK_END); //移到尾部
len = ftell(file); //提取长度
rewind(file); //回归原位
CCLOG("count the file content len = %d",len);
//分配buf空间
buf = (char*)malloc(sizeof(char) * len + 1);
if (!buf) {
CCLOG("malloc space is not enough.");
return NULL;
}