I am trying to store a leaderboard locally for the game I am working on. To do this, I have added a text file to the resource folder inside my program. I am attempting to write to and read from this file in order to fill up my leaderboard, but I cannot figure out a way to access it inside the C# program. Everything online is extremely difficult to understand, and I am fairly new to this language. I will provide screenshots of what I think to be important to this.
I cannot put the text file image into this question but I can input the code.
This is for the string writer part...
`` string fileName = "Scoreboard.txt";
string filePath = Path.Combine(FileSystem.AppDataDirectory, fileName);
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine(Convert.ToString(balance));
}
``
This is for the string reader part...
`` string fileName = "Scoreboard.txt";
string filePath = Path.Combine(FileSystem.AppDataDirectory, fileName);
using (StreamReader reader = new StreamReader(filePath))
{
string line = reader.ReadLine();
while(line != null)
{
LeaderBoard.Add(Convert.ToInt32(line));
line = reader.ReadLine();
}
}
``
I've tried multiple ways of accessing the file, but it will not work, and I cannot use my file path as it uses my username, which means it would not work for everyone. Any help would be greatly appreciated.