Answers for "c# readalltext"

C#
6

c# read all text from a file

using (StreamReader streamReader = new StreamReader(path_name, Encoding.UTF8))
{
  contents = streamReader.ReadToEnd();
}
Posted by: Guest on April-22-2020
0

c# readalltext

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string value1 = File.ReadAllText("C:\\file.txt");
        string value2 = File.ReadAllText(@"C:\file.txt");
        
        Console.WriteLine("--- Contents of file.txt: ---");
        Console.WriteLine(value1);
        
        Console.WriteLine("--- Contents of file.txt: ---");
        Console.WriteLine(value2);
    }
}
--- Contents of file.txt: ---
(Text)
--- Contents of file.txt: ---
(Text)
Posted by: Guest on August-31-2021

C# Answers by Framework

Browse Popular Code Answers by Language