프로젝트/Color Lim 개발일지

File.ReadAllText와 StreamReader.ReadToEnd의 차이점

https://stackoverflow.com/questions/3545402/any-difference-between-file-readalltext-and-using-a-streamreader-to-read-file

 

Any difference between File.ReadAllText() and using a StreamReader to read file contents?

At first I used a StreamReader to read text from a file: StreamReader reader = new StreamReader(dialog.OpenFile()); txtEditor.Text = reader.ReadToEnd(); but found out about File.ReadAllText which...

stackoverflow.com

 

[SecurityCritical]
private static string InternalReadAllText(string path, Encoding encoding, bool checkHost)
{
    string result;
    using (StreamReader streamReader = new StreamReader(path, encoding, true, StreamReader.DefaultBufferSize, checkHost))
    {
        result = streamReader.ReadToEnd();
    }
    return result;
}

File.ReadAllText는 내부적으로 StreamReader.ReadToEnd를 호출한다