How to read a text file on Windows RT lines?

I just can't find a clear explanation of how to read a text file, one at a time in Windows RT (for the Windows 8 Store).

Suppose I have a folder: MyFolder/Notes.txt

And I want to read the data from Notes.txt and add it to the string array.

How do I read / write from this file? I used to use StreamReader, but now it is very confusing. And the dev samples don't really help.

+4
source share
3 answers

I myself managed to find the answer. Thanks for the help.

  // READ FILE public async void ReadFile() { // settings var path = @"MyFolder\MyFile.txt"; var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; // acquire file var file = await folder.GetFileAsync(path); var readFile = await Windows.Storage.FileIO.ReadLinesAsync(file); foreach (var line in readFile) { Debug.WriteLine("" + line.Split(';')[0]); } } 

MyFile.txt has:

Test1; Description1;

Test2; Description2;

// Exit For ReadFile ()

Test1

Test2

+7
source

You do not need to use File.ReadLines . You are trying to implement such an implementation if you want:

 using (StreamReader reader = new StreamReader("notes.txt")) { while (reader.Peek() >= 0) { Console.WriteLine(reader.ReadLine()); } } 
+3
source
 foreach (var line in File.ReadLines("MyFolder/Notes.txt")) { ... } 

reads a file line by line. This is different from File.ReadAllLines , which immediately reads the entire file.

If you want to read everything at once, into an array, use the latter.

+2
source

All Articles