using System.IO; class Program { static void Main(string[] args) { StreamReader reader = new StreamReader("textfile.txt"); string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } reader.Close(); } }
using System.IO; using System.Net; class Program { static void Main(string[] args) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.example.com"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string responseText = reader.ReadToEnd(); reader.Close(); response.Close(); Console.WriteLine(responseText); } }The System.IO.StreamReader class is included in the .NET framework and is a part of the System.IO namespace.