We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp GuidesQuick GameRuntime Quick GameBasic CapabilitiesFile System

File System

The file system, offered by HUAWEI Quick Game, offers storage isolated by game and user, along with a suite of management API. The global object qg provides access to the globally unique file system manager. All file system management operations are handled through qg, specifically via the qg.getFileSystemManager() API.

The files are classified into two types:

  • Code package files: files added to the game development project.
  • Local files: files generated locally by calling relevant APIs, or downloaded from the network and saved locally.

Local files can also be classified into two types:

  • Local temporary files: The files are generated temporarily and will be recycled at any time. There is no limitation on their sizes.
  • Local user files: The files are generated after local temporary files are cached by a quick game through relevant APIs. The directories and names of these files are customizable. They are saved in a quick game until the quick game is deleted by a user. The total size of local user files in a quick game cannot exceed 200 MB.

Code Package Files

Due to the size limitation, a code package should only include files for initial loading, rather than large files or files in dynamic replacement. You are advised to download large files or files in dynamic replacement by API and save them as local files after the quick game is launched.

A code package file path complies with the following requirements:

  • The code package file path must be a relative file path starting from the root directory of the game package. Any other types of relative file paths are not supported.
  • You can use an absolute path that must start from the root directory of the game package.

Local Files

Local files are saved in an isolated storage space that is allocated after a quick game is loaded. They are identified by HUAWEI ID. That is to say, files are isolated by both account and game. Users cannot access data from other HUAWEI IDs on the same device, nor can they access files across different games.

Local Temporary Files

Local temporary files can be created only by calling specific APIs and are not editable. They are only accessible during the session they were created and will become unavailable once the game is re-launched. Therefore, please do not save a local temporary file path for future use. If a local temporary file is required for future use, you can call FileSystemManager.saveFile() or FileSystemManager.copyFile() to convert it into a local user file.

Local User Files

HUAWEI Quick Game provides a user file directory for you, and you have full read and write permissions on the directory. You can obtain the path of the directory by calling qg.env.USER_DATA_PATH.

Read and Write Permissions

Expand

File Type

Readable

Writable

Code package files

Yes

No

Local temporary files

Yes

No

Local user files

Yes

Yes

Sample Code

Collapse
Word wrap
Dark theme
Copy code
  1. const fs = qg.getFileSystemManager();
  2. fs.writeFile({
  3. filePath: `${qg.env.USER_DATA_PATH}/${fileName}`,
  4. data: "Hello world",
  5. encoding: "utf8",
  6. success: successCb,
  7. fail: failCb
  8. });
Search in Guides
Enter a keyword.