Where does File.read() look after build? How do you include random raw files in the build so they are still accessible?

I see it is quite easy to read files (text) using File.read("filename.txt") as per here:

From what I see, if you run your project with iex -S mix it looks in the root folder of the project (where you run this command from).

But what happens if you build the project like following these instructions?

Where will it look in the final build? If you have file.txt in your root project directory and are accessing that in code via File.read("file.txt") will it still find it after this process? Will the path be the same?

How do we ensure the file is included in the build tar so that it still can be found?

Thanks for any help.

Use the priv/ dir under the project root. The content will be built into the release.

File.read(Path.join([:code.priv_dir(:my_app), "finename.txt"]))
3 Likes