How to write and read a text file in C#

using System;

using System.IO;

class Class

{

    static void Main()

    {
         // Write out to text file

         StreamWriter writer = File.CreateText("c:\\me.doc");

         writer.WriteLine("Arshad you are Out of file.");

         writer.Close();

         // Read all lines from text file

         StreamReader reader = File.OpenText("c:\\me.doc");

         string line = reader.ReadLine();

         while (line != null)

         {

              Console.WriteLine(line);

              line = reader.ReadLine();

         }

         reader.Close();

     }
} 

Ebook Download
View all
Learn
View all