John
John

Reputation: 125

WP8 write lines of text

I have a complete game that I am converting to windows phone. I am almost ready except for saving and loading a txt file. In c# for windows it would work like this: Saving:

string[] lines = {myValue.ToString(),myValue2.ToString()}
System.IO.File.WriteAllLines(path+"/myFileName.txt", lines);

This generates a file which looks like this:

1

5

separate lines for each value

Reading:

string f = path + "/myFileName.txt";
            var lines = File.ReadAllLines(f);
            myValue = Convert.ToInt64(lines[0]);
            myValue2 = Convert.ToInt64(lines[1]);

this would give myValue=1 and myValue2=5

How can I do this on Windows Phone (separate lines)?

Upvotes: 0

Views: 133

Answers (1)

Cole Campbell
Cole Campbell

Reputation: 4857

Use Isolated Storage to retrieve a stream to the file in question, then create an instance of StreamReader and read its lines in the usual way.

Microsoft has provided example code: Writing Data (Windows Phone)

Upvotes: 1

Related Questions