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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s