Stream.CopyTo reads all the bytes from the current stream and writes them to the destination stream.
using System;
using System.IO;
class TestRW
{
public static void Main(String[] args)
{
MemoryStream destination = new MemoryStream();
using (FileStream source = File.Open(@"c:\temp\data.dat",FileMode.Open))
{
Console.WriteLine("Source length: {0}", source.Length.ToString());
source.CopyTo(destination);
}
Console.WriteLine("Destination length: {0}", destination.Length.ToString());
}
}
Related examples in the same category