Cocos2d-x 3.x文件操作

FileUtils类是cocos2d提供的文件操作类。

简介

FileUtils:处理文件操作的通用工具类,是个单例类,提供了整个引擎资源文件的默认搜索路径。(资源文件的默认搜索路径是 :Resources文件夹)。


与路径相关API

  • 获得搜索路径
virtual const std::vector < std::string > &     getSearchPaths () const
  • 增加搜索路径

void addSearchPath (const std::string &path, const bool front=false)

示例:在Resources/im文件下有图片h.png。

FileUtils::getInstance()->addSearchPath("im");
Sprite * sp = Sprite::create("h.png");
  • 设置默认搜索路径 : 绝对路径
void setDefaultResourceRootPath (const std::string &path)
  • 设置路径
void setSearchPaths (const std::vector< std::string > &searchPaths)
  • 检测文件是否存在
bool isFileExist (const std::string &filename) const
  • 返回文件的完整文件路径
std::string fullPathForFilename (const std::string &filename) const
  • 根据文件名和相对路径返回完整路径
std::string fullPathFromRelativeFile (const std::string &filename, const std::string &relativeFile)


与文件操作相关API

  • 删除文件
bool removeFile (const std::string &filepath)
  • 获得文件大小
long getFileSize (const std::string &filepath)
  • 创建文件夹
bool createDirectory (const std::string &dirPath)
  • 删除文件夹
bool removeDirectory (const std::string &dirPath)
  • 判断路径是否是文件夹
bool isDirectoryExist (const std::string &dirPath) const
  • 获得文件内容的字符串信息
std::string getStringFromFile (const std::string &filename)
  • 将一个文件内容读取为二进制数据
Data getDataFromFile (const std::string &filename)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值