Reading from a text file line by line : Stream Read Write : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Stream Read Write »

 

Reading from a text file line by line








    
 


using System;
using System.IO;

class MainClass {
    public static void Main(string[] args) {
        try {
            FileStream fs = new FileStream("c:\\a.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            string line = "";

            int lineNo = 0;
            do {
                line = sr.ReadLine();
                if (line != null) {
                    Console.WriteLine("{0}: {1}", lineNo, line);
                    lineNo++;
                }
            } while (line != null);
        } catch (Exception e) {
            Console.WriteLine("Exception in ShowFile: {0}", e);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Stream Read Write