File I/O

Closing files

To close a file, use the close method:

file.close()

Reading and writing

To read from a file, use the get_as_text or other get_* method:

var file = FileAccess.open("user://save_game.dat", FileAccess.READ)
var player_name = file.get_as_text()
print(player_name)

Writing a file

To write to a file, use the store_string, store_line or other store_* methods:

var player_name = "Septian"
var file = FileAccess.open("user://save_game.dat", FileAccess.WRITE)
file.store_string(player_name)
Comments