StreamReader 클래스

[ 출처 : https://msdn.microsoft.com/ko-kr/library/system.io.streamreader(v=vs.110).aspx ]


StreamReader 클래스 

: 특정 인코딩의 바이트 스트림에서 문자를 읽는 TextReader를 구현합니다.


ReadLine현재 스트림에서 한 줄의 문자를 읽고 데이터를 문자열로 반환합니다. (TextReader.ReadLine()을(를) 재정의함)
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            // Create an instance of StreamReader to read from a file.
            // The using statement also closes the StreamReader.
            using (StreamReader sr = new StreamReader("TestFile.txt")) 
            {
                string line;
                // Read and display lines from the file until the end of 
                // the file is reached.
                while ((line = sr.ReadLine()) != null) 
                {
                    Console.WriteLine(line);
                }
            }
        }
        catch (Exception e) 
        {
            // Let the user know what went wrong.
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }
    }
}