How to read .txt file in C#

Below code will return the text of a file

var text = new StringBuilder();
            var stream = new FileStream(path, FileMode.OpenOrCreate);
            using (var reader = new StreamReader(stream))
            {
                while (reader.Peek() >= 0)
                    text.AppendLine(reader.ReadLine());
            }
            text.ToString();

Leave a Reply

Your email address will not be published. Required fields are marked *