.NET 4.0 New Feature - Stream.CopyTo
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { using (MemoryStream sourceStream = new MemoryStream(512)) { using (StreamWriter sw = new StreamWriter(sourceStream)) { sw.WriteLine(“Test Stream.CopyTo”); sw.Flush();
sourceStream.Seek(0, SeekOrigin.Begin);
using (FileStream targetStream = new FileStream("Test.Txt", FileMode.Create))
{
sourceStream.CopyTo(targetStream);
}
}
}
}
}
}