new StreamReader(FileStream fs) : StreamReader « System.IO « C# / C Sharp by API






new StreamReader(FileStream fs)

 


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);
        }
    }
}

   
  








Related examples in the same category

1.new StreamWriter(String filePath)
2.new StreamWriter(fs, Encoding.UTF8)
3.StreamReader.Peek()
4.StreamReader.ReadLine()
5.StreamReader.ReadToEnd()