# How to import and read text?

**URL:** <https://forum.godotengine.org/t/how-to-import-and-read-text/21936>\
**Category:** Archive\
**Created:** [December 15, 2019, 10:31pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936 "2019-12-15T22:31:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [December 15, 2019, 10:31pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/1 "2019-12-15T22:31:12Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | Setherino |

I need to store a lot of text for my game. I also need to be able to edit it in-editor. The obvious solution to this is text files, but I can’t seem to get them to work in Godot.

My first thought was to create a new resource, and make it a text file. This gave me a .tres file which acted as a text file. This was fine, until the contents of the file deleted themselves, and were replaced with “[resource]”. Or, until Godot forgot that it was a text file, and tried to open it as a scene.

 ![new resource panel, with TextFile selected](https://forum.godotengine.org/uploads/default/original/2X/e/e553e5efde7c708b9ce46f5cfa9e2f5837c491b1.png)

Then I thought I’d use a txt file, but Godot just wouldn’t let me import that at all. After some research I tried a .csv file, and while it was imported, it couldn’t be edited in-editor, and filled the console with errors.

So, how do I import a text file that I can change in-editor? Is this even possible?

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [December 15, 2019, 11:34pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/2 "2019-12-15T23:34:56Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | johnygames |

Basically what you want to do is load a file and read its content. You can do that by placing a .txt file in your project folder. Then you store the file’s path in a variable named “file”. Then you need to open said file and do whatever you want with its content. The following example opens a specified file, goes though it line by line and prints out each line unitl the end of the file is reached.

```auto
extends Node2D

onready var file = 'res://foobar.txt'

func _ready():
	load_file(file)

func load_file(file):
	
	var f = File.new()
	f.open(file, File.READ)
	var index = 1
	while not f.eof_reached(): # iterate through all lines until the end of file is reached
		var line = f.get_line()
		line += " "
		print(line + str(index))

		index += 1
	f.close()
	return

```

Place the above code in your main node or wherever you think is necessary. I hope this helps.

This works, but when I export the project to Android, the text file isn’t bundled it seems and I get a read error ☹  
The text file doesn’t have a corresponding .import file and I’m not sure how to create one… Not sure if that’s the reason why it doesn’t get bundled in the final APK.

endavid | 2022-03-20 21:03

When I get to the get\_line, it comes back with a NULL value after a bit of a pause. The file is big (360M), could this be too big for this function to read?

```auto
var line = f.get_line()

```

grymjack | 2023-01-11 01:37

---

<div class="post-metadata">

**Author:** ![st\_phan](https://forum.godotengine.org/user_avatar/forum.godotengine.org/st_phan/32/24252_2.png) [@st\_phan](https://forum.godotengine.org/u/st_phan)\
**Post date:** [July 28, 2024, 5:57pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/3 "2024-07-28T17:57:46Z")

</div>

In Godot 4, this is now much easier via [the FileAccess API](https://docs.godotengine.org/en/stable/classes/class_fileaccess.html):

```auto
var text_file_path = "res://text_folder/some_text_file.txt"

func _ready():
	var text_content = get_text_file_content(text_file_path)

func get_text_file_content(filePath):
	var file = FileAccess.open(filePath, FileAccess.READ)
	var content = file.get_as_text()
	return content

```

---

<div class="post-metadata">

**Author:** ![heinzl](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/h/c67d28/32.png) [@heinzl](https://forum.godotengine.org/u/heinzl)\
**Post date:** [October 5, 2024, 2:46pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/4 "2024-10-05T14:46:26Z")

</div>

Note: You cannot access a text file with a resource path in the exported project, unless you add a filter \*.txt to “Filters to export non-resoucre files/folders” under Project → Export → Resources tab.

---

<div class="post-metadata">

**Author:** ![sooooooda](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@sooooooda](https://forum.godotengine.org/u/sooooooda)\
**Post date:** [March 7, 2025, 1:35am UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/5 "2025-03-07T01:35:13Z")

</div>

if you don’t need to alter the text content at all before returning it, you can just return the callable itself. you don’t HAVE to set it to a variable first.

---

<div class="post-metadata">

**Author:** ![ubershmekel](https://forum.godotengine.org/user_avatar/forum.godotengine.org/ubershmekel/32/65362_2.png) [@ubershmekel](https://forum.godotengine.org/u/ubershmekel)\
**Post date:** [January 22, 2026, 11:05am UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/6 "2026-01-22T11:05:28Z")

</div>

Feels odd that the only way to include txt files is by modifying every export template. I wish there was a way to either `include_filter=“*.txt”` in all of the presets or some other way to modify what gets packaged like by having something like `gd.import` files that define what gets packaged.

---

<div class="post-metadata">

**Author:** ![paintsimmon](https://forum.godotengine.org/user_avatar/forum.godotengine.org/paintsimmon/32/45257_2.png) [@paintsimmon](https://forum.godotengine.org/u/paintsimmon)\
**Post date:** [January 22, 2026, 5:57pm UTC](https://forum.godotengine.org/t/how-to-import-and-read-text/21936/7 "2026-01-22T17:57:10Z")

</div>

You should make a proposal on GitHub for it!
