DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Reading A Text File With StreamReader

06.01.2006
| 38003 views |
  • submit to reddit
        
  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();
    }
  }