Answers for "c# get stream from file"

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
0

return stream from file c#

private void Test()
{            
    System.IO.MemoryStream data = new System.IO.MemoryStream(TestStream());

    byte[] buf = new byte[data.Length];
    data.Read(buf, 0, buf.Length);                       
}
Posted by: Guest on November-09-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