Write text file line by line : Text File Read Write : File Directory Stream C# Examples


C# Examples » File Directory Stream » Text File Read Write »

 

Write text file line by line









    
using  System;
using  System.IO;

class  MainClass
{
    public  static  void  Main()  
    {
        FileStream  outStream  =  File.Create("c:\\Test.txt");
        StreamWriter  sw  =  new  StreamWriter(outStream);

        sw.WriteLine("This  is  a  test  of  the  StreamWriter  class");

        sw.Flush();
        sw.Close();

        StreamReader  sr  =  new  StreamReader("c:\\Test.txt");

        string  FirstLine;
    
        FirstLine  =  sr.ReadLine();
        Console.WriteLine(FirstLine);

        sr.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Text File Read Write