Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

FileAccess

Inherits: RefCounted < Object

Provides methods for file reading and writing operations.

Description

This class can be used to permanently store data in the user device's file system and to read from it. This is useful for store game save data or player configuration files.

Here's a sample on how to write and read from a file:

func save(content):
    var file = FileAccess.open("user://save_game.dat", FileAccess.WRITE)
    file.store_string(content)

func load():
    var file = FileAccess.open("user://save_game.dat", FileAccess.READ)
    var content = file.get_as_text()
    return content

In the example above, the file will be saved in the user data folder as specified in the Data paths documentation.

FileAccess will close when it's freed, which happens when it goes out of scope or when it gets assigned with null. close can be used to close it before then explicitly. In C# the reference must be disposed manually, which can be done with the using statement or by calling the Dispose method directly.

Note: To access project resources once exported, it is recommended