- Home /
Set String Array or List to .txt File in a Builds Data Folder
Hello! After building a game if I go into the data folder for the game and create a .txt file, in this case we'll call it "strings," how could I access that .txt file in a C# script, and set each line in that .txt file to a string element in an array or list? I only need to read from the .txt file, not write to it. Thank you!
Answer by Bunny83 · Apr 26, 2020 at 04:17 AM
Well just use those two lines:
string filename = System.IO.Path.Combine(Application.dataPath, "strings.txt");
string[] lines = System.IO.File.ReadAllLines(filename);
if you want a list instead of course you can simply do
List<string> lines = new List<string>(System.IO.File.ReadAllLines(filename));
Answer by Epicnez · Apr 26, 2020 at 04:37 AM
@Bunny83 Thanks! It worked perfectly, I didn't know there was a Application.dataPath, so thank you for teaching me that! (EDIT: Gave you a reputation point, it's my first time doing that so I hope it worked! Thank you so much again!)
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
NPC dialogue - Loading a text file to a string? 1 Answer
GUI HELP!!!!! 1 Answer
Texts As Objects? 1 Answer