Read text file line by line

image_pdfimage_print
   
  
using System;
using System.IO;

public class ReadWriteApp
{
    public static void Main(string[] args)
    {
        FileStream s = new FileStream("Bar.txt", FileMode.Create);
        StreamWriter w = new StreamWriter(s);
        w.Write("Hello World");
        w.Close();
   
        s = new FileStream("Bar.txt", FileMode.Open);
        StreamReader r = new StreamReader(s);
        string t;
        while ((t = r.ReadLine()) != null)
        {
            Console.WriteLine(t);
        }
        w.Close();
    }
}

   
     


This entry was posted in File Stream. Bookmark the permalink.