C# MemoryStream CopyTo(Stream)
Description
MemoryStream CopyTo(Stream)
Reads the bytes from the
current stream and writes them to another stream.
Syntax
MemoryStream.CopyTo(Stream)
has the following syntax.
public void CopyTo(
Stream destination
)
Parameters
MemoryStream.CopyTo(Stream)
has the following parameters.
destination
- The stream to which the contents of the current stream will be copied.
Returns
MemoryStream.CopyTo(Stream)
method returns
Example
The following example copies the contents of a FileStream to a MemoryStream.
/*from ww w .j a v a 2 s . com*/
using System;
using System.IO;
public class MainClass{
public static void Main(String[] argv){
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());
}
}