File System Access

Even though you can use functions in stdio.h to access files it can be inconvenient for a few reasons:

  • You need to invoke system specific API to get full path of a file.
  • Resources are packed into .apk file on Android after installing.
  • You want to load a resource (such as a picture) based on resolution automatically.

The FileUtils class has been created to resolve these issues. FileUtils is a helper class to access files under the location of your Resources directory. This includes reading data from a file and checking file existence.

Functions to read file content

These functions will read different type of files and will return different data types:

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 std::string cocos2d::ValueVector

Functions to manage files or directories

These functions will manage a file or a directory:

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

results matching ""

    No results matching ""