Reputation: 75
I have a txt file that is in my content folder for my XNA game. I have been able to read data from that file using the stream reader; however I was not able to write strings to it using the stream*writer* because it says I cannot write to the stream.
I use the content folder so that I may store high scores externally and that I may publish the game with the high score txt. I need to add the string "OEB 3350" to this file.
The location of my file is "Content\leaderboard.txt"
How does one write to this txt file.
public void updateExternalLeaderboard()
{
string[] leaderboardArray = new string[orderedScoreList.Count];
System.IO.Stream stream = TitleContainer.OpenStream("Content\\leaderboard.txt");
System.IO.StreamWriter swriter= new System.IO.StreamWriter(stream);
for (int p = 0; p < orderedScoreList.Count; p++)
{
leaderboardArray[p] = orderedScoreList[p].initials + " " + orderedScoreList[p].scoreString;
swriter.WriteLine(leaderboardArray[p]);
}
swriter.Close();
}
Upvotes: 1
Views: 3317
Reputation: 14153
Check out Saving Data to a Game File
You have to serialize and use a storage container. The tutorial has a full project so it has alot of methods to do it.
Upvotes: 1