System.IO.Stream.CopyTo 方法 (Stream)
方法描述
从当前流中读取字节并将其写入到目标流中。
语法定义(C# System.IO.Stream.CopyTo 方法 (Stream) 的用法)
public void CopyTo( Stream destination )
参数/返回值
| 参数值/返回值 | 参数类型/返回类型 | 参数描述/返回描述 | 
|---|---|---|
| destination | System-IO-Stream | 将包含当前流的内容的流。 | 
| 返回值 | void | 
提示和注释
复制从当前流中的当前位置开始。
System.IO.Stream.CopyTo 方法 (Stream)例子
下面的示例将 FileStream 的内容复制到 MemoryStream 中。
// Create the streams.
MemoryStream destination = new MemoryStream();
using (FileStream source = File.Open(@"c:\temp\data.dat",
    FileMode.Open))
{
    Console.WriteLine("Source length: {0}", source.Length.ToString());
    // Copy source to destination.
    source.CopyTo(destination);
}
Console.WriteLine("Destination length: {0}", destination.Length.ToString());
异常
| 异常 | 异常描述 | 
|---|---|
| ArgumentNullException | destination 为 null。 | 
| NotSupportedException | 
 | 
| ObjectDisposedException | 在调用 CopyTo 方法之前关闭了当前流或 destination。 | 
| IOException | 发生了 I/O 错误。 | 
版本信息
.NET Framework 受以下版本支持:4 .NET Framework Client Profile 受以下版本支持:4
适用平台
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。