User Tools

Site Tools

blog:2024-08-13_c_read_a_text_file_line-by-line



2024-08-13 C#: Read a text file line-by-line

  • I want to read a text file line by line in console mode.
  • Here is an efficient method within the .NET C# scope.
  • const Int32 BufferSize = 128;
    using (var fileStream = File.OpenRead(fileName))
      using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize)) {
        String line;
        while ((line = streamReader.ReadLine()) != null)
        {
          // Process line
        }
      }

Reference

TAGS

  • 20 person(s) visited this page until now.

Permalink blog/2024-08-13_c_read_a_text_file_line-by-line.txt · Last modified: 2024/08/13 17:40 by jethro

oeffentlich