Read a text file - CSharp File IO

CSharp examples for File IO:Text File

Description

Read a text file

Demo Code

using System;//from  w  ww.j a va2s .  c o  m
using System.IO;
class Program
{
   static void Main(string[] args)
   {
      StreamReader reader = new StreamReader("main.cs");
      string contents = reader.ReadToEnd();
      Console.WriteLine("File contents:");
      Console.WriteLine(contents);
      reader.Close();
   }
}

Result


Related Tutorials