Read Text File

Code


const string filePath = ".\names.txt";

[TestMethodAttribute("File.ReadAllText")]
public void Method0()
{
string allData = File.ReadAllText(filePath);
}

[TestMethodAttribute("StreamReader.ReadToEnd")]
public void Method1()
{
StreamReader sr = new StreamReader(filePath);
string allData = sr.ReadToEnd();
sr.Close();
sr.Dispose();
sr = null;
}

[TestMethodAttribute("BinaryReader.ReadString")]
public void Method2()
{
StreamReader sr = new StreamReader(filePath);
BinaryReader br = new BinaryReader(sr.BaseStream);
string allData = br.ReadString();
br.Close();
br.Dispose();
br = null;
sr.Close();
sr.Dispose();
sr = null;
}

Results

image0

Links

Buffer