Tuesday, September 10, 2013

c# Read Text File

To read all text at once 

using System.IO;

string fileLocation= @"C:\myFile.txt";
string allText = File.ReadAllText(fileLocation);

To read line by line

using System.IO;

string fileLocation= @"C:\myFile.txt";
using (StreamReader streamReader = File.OpenText(fileLocation))
    while (streamReader.Peek() >= 0)

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator