cocos 读写操作

#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS

    auto xx_imgs = FileUtils::getInstance()->fullPathForFilename(filename);

    return xx_imgs;

#else

    // 资源路径

    std::string sourcePath = cocos2d::FileUtils::getInstance()->fullPathForFilename(filename);

    // 可写路径

    std::string destPath = cocos2d::FileUtils::getInstance()->getWritablePath() + filename;

    if (cocos2d::FileUtils::getInstance()->isFileExist(destPath)) {

        return destPath;

    }

扫描二维码关注公众号,回复: 9827083 查看本文章

    if (cocos2d::FileUtils::getInstance()->isFileExist(destPath + ".tmp")) {

        cocos2d::FileUtils::getInstance()->removeFile(destPath + ".tmp");

    }

    

    // write

    cocos2d::Data data = cocos2d::FileUtils::getInstance()->getDataFromFile(sourcePath);

    FILE *fp = fopen(destPath.c_str(), "w+");

    if (fp)

    {

        size_t size = fwrite(data.getBytes(), sizeof(unsigned char), data.getSize(), fp);

        fclose(fp);

        

        if (size > 0)

        {

            return destPath;

        }

    }

    CCLOG("copy file %s failed.", filename.c_str());

    return "";

#endif

发布了12 篇原创文章 · 获赞 0 · 访问量 5032

猜你喜欢

转载自blog.csdn.net/ZhaoLuoss/article/details/81079920