- Home /
Question by
PlayCreatively · Sep 14, 2020 at 08:37 PM ·
textbuild-erroriotxtfilepath
DirectoryNotFoundException when running a build
I'm having issues reading a txt file from the Assets folder when running a build. No problem when running in the editor.
FileNotFoundException: Could not find file "C:\Users\lexi-\Desktop\Builds\Dont Sleep_Data\lostClothes.txt"
Here's the code I'm using.
public static string Get(string fileName)
{
string path = $"{Application.dataPath}/{fileName}.txt";
return File.ReadAllText(path);
}
Comment
Best Answer
Answer by PlayCreatively · Sep 18, 2020 at 03:48 AM
Using Resources.Load instead of System.IO.File fixed everything. Take note, using Resources.Load requires you to make a folder called "Resources" in the Assets folder and storing the files there. This is how my function looks now.
public static string Get(string fileName) => Resources.Load<TextAsset>($"Dialogue/{fileName}").text;
Your answer
![](https://koobas.hobune.stream/wayback/20220613011845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Read txt file from Android Downloads file 1 Answer
parsing csv file 2 Answers
Read text file to get 2D array 1 Answer
Read txt into string array, recognize as commands with arguments 1 Answer
Create Text File 3 Answers