Saturday, May 30, 2009

Reading a text file with StreamReader

// Reading a text file with StreamReader

private void ImportCountries()
{
string delimiter = ",";
string fileName = @"c:\countrylist3.csv";

StreamReader sr = new StreamReader(fileName);

try
{
while (sr.Peek() >= 0)
{
string r = sr.ReadLine();
string[] items = r.Split(delimiter.ToCharArray());
}
}
finally
{
sr.Close();
}
}

No comments:

Post a Comment