Cocos2d-x 文件系统学习笔记 分类: cocos2d代码编写 2015-07-27 19:04 5人阅读 评论(0) 收藏

文件系统访问


尽管你可以使用stdio.h头文件中的函数来访问文件,但这种方式是不太方便的,原因是:你需要激活系统特定的API接口来获取文件的完整地址。在安卓系统上安装之后,资源都被打包成了.apk文件。*希望能够基于分辨率自动加载资源(如一张图片)。


创建FileUtils类正是为解决这些问题。FileUtils是在Resources下访问文件的一个辅助类。它可以文件中读取数据和检查文件是否存在。


读取文件内容的函数


这些函数会读取不同类别的文件并返回不同的数据类型:


| function name | return type | support path type |


| getStringFromFile | std::string | relative path and absolute path |


| getDataFromFile | cocos2d::Data | relative path and absolute path |


| getFileDataFromZip | unsigned char* | absolute path |


| getValueMapFromFile | cocos2d::ValueMap | relative path and absolute path |


| getValueVectorFromFile | cocos2d::ValueVector | relative path and absolute path |


管理文件及目录的函数


这些函数能够管理文件或者目录:


| function name | support path type |


| isFileExist | relative path and absolute path |


| isDirectoryExist | relative path and absolute path |


| createDirectory | absolute path |


| removeDirectory | absolute path |


| removeFile | absolute path |


| renameFile | absolute path |


| getFileSize | relative path and absolute path |

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-07-27 19:04  leansmall  阅读(223)  评论(0编辑  收藏  举报