how to create a file in godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Daniel Schechtman
:warning: Old Version Published before Godot 3 was released.

I’m not just talking about from a gdscript either. I want to know how to make something like a txt file both from godot UI and from a gdscript

:bust_in_silhouette: Reply From: whooshfrosted
static func write_file(file_name, string):
	var file = File.new()
	file.open(file_name, File.WRITE)
	file.store_string(string)
	file.close()

static func read_file(file_name):
	var file = File.new()
	if !file.file_exists(file_name):
		return

	file.open(file_name, File.READ)

	var array = []
	while(!file.eof_reached()):
		var line = file.get_line()
		array.push_back(line)

	file.close()
	return array

I recommend that you create your files in the “user://” path because different platforms may forbid write access to certain paths (including res://).

File system — Godot Engine (stable) documentation in English

wombatstampede | 2017-07-20 16:07