Reading Text from a File - CSharp File IO

CSharp examples for File IO:Text File

Description

Reading Text from a File

Demo Code

using System;//from   w  w w  .j av  a  2s .c om
using System.IO;
public class Reading
{
   public static void Main(String[] args)
   {
         string buffer;
         StreamReader myFile = File.OpenText("main.cs");
         while ( (buffer = myFile.ReadLine()) != null )
         {
            Console.WriteLine(buffer);
         }
         myFile.Close();

   }
}

Result


Related Tutorials