StreamReader.ReadLine() : StreamReader « System.IO « C# / C Sharp by API






StreamReader.ReadLine()

 
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

class Program {
    static void Main(string[] args) {
        string strLine;

        try {
            FileStream aFile = new FileStream("Log.txt", FileMode.Open);
            StreamReader sr = new StreamReader(aFile);
            strLine = sr.ReadLine();
            while (strLine != null) {
                Console.WriteLine(strLine);
                strLine = sr.ReadLine();
            }
            sr.Close();
        } catch (IOException e) {
            Console.WriteLine("An IO exception has been thrown!");
            Console.WriteLine(e.ToString());
            return;
        }
    }
}

   
  








Related examples in the same category

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