FileUtils* f = FileUtils::getInstance();
//获得可写的具体文件路径
std::string path = f -> getWritablePath();
std::string xmlPath = path + filename;
log("xmlPath = %s",xmlPath.c_str());
if (f ->isFileExist(xmlPath)) {
log("可写的具体文件路径中文件存在");
}else{
log("可写的具体文件路径中文件不存在");
//获得app中存储路径(资源路径下的)
std::string sourcePath = f -> fullPathForFilename(filename);
log("path2 = %s",sourcePath.c_str());
//读取内容(纯字符串数据)
#if 0
std::string fileContent = f -> getStringFromFile(sourcePath);
log("%s",fileContent.c_str());
//写入
FILE* file = fopen(xmlPath.c_str(), "wb");
if (file) {
fputs(fileContent.c_str(), file);
fclose(file);
}
#endif
//读取内容(任何文件从资源路径拷贝到可写路径下)
#if 1
Data data = FileUtils::getInstance()->getDataFromFile(sourcePath);
//写入
FILE* file = fopen(xmlPath.c_str(), "w+");
if (file) {
size_t size = fwrite(data.getBytes(), sizeof(unsigned char), data.getSize(), file);
fclose(file);
if (size <= 0)
{
log("拷贝%s到可写路径失败",filename.c_str());
}
}
#endif
}
附录:
fopen()参数说明:
参数path字符串包含欲打开的文件路径及文件名,参数mode字符串则代表着流形态。