Answers for "convert stream to streamreader c#"

C#
4

c# streamreader

// The StreamReader are using the Namespaces: System and system.IO

using (StreamReader sr = new StreamReader("TestFile.txt"))
{
  string line;
  while ((line = sr.ReadLine()) != null)
  {
    Console.WriteLine(line);
  }
}
Posted by: Guest on March-04-2021
0

c# streamreader to file

// after .NET 4.0
using (var fileStream = File.Create("C:\Path\To\File"))
{
    myOtherObject.InputStream.Seek(0, SeekOrigin.Begin);
    myOtherObject.InputStream.CopyTo(fileStream);
}

// before .NET 4.0
public static void CopyStream(Stream input, Stream output)
{
    byte[] buffer = new byte[8 * 1024];
    int len;
    while ( (len = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        output.Write(buffer, 0, len);
    }

	// streams are not closed
}
Posted by: Guest on February-24-2021

C# Answers by Framework

Browse Popular Code Answers by Language