Answers for "get file as stream c#"

3

c# read file stream

using System;
using System.IO;
using System.Text;

namespace StreamReaderReadToEnd
{
    class Program
    {
        static void Main(string[] args)
        {
            var path = @"C:UsersJanoDocumentsthermopylae.txt";

            using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            using var sr = new StreamReader(fs, Encoding.UTF8);
            
            string content = sr.ReadToEnd();

            Console.WriteLine(content);
        }
    }
}
Posted by: Guest on February-17-2020
2

c# read file stream

//this will get a string with all the text from the file
var fileText = File.ReadAllText(@"pathtomyfile.txt");

//this will get all of the lines of the file as an string[]
var fileLines = File.ReadAllLines(@"pathtomyfile.txt");
Posted by: Guest on February-17-2020

Browse Popular Code Answers by Language