Stream.CopyTo 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從目前串流讀取位元組,然後寫入另一條串流。 兩個串流的位置依複製的位元組數前進。
多載
| 名稱 | Description |
|---|---|
| CopyTo(Stream) |
從目前串流讀取位元組,然後寫入另一條串流。 兩個串流的位置依複製的位元組數前進。 |
| CopyTo(Stream, Int32) |
從目前串流讀取位元組,並依指定緩衝區大小寫入另一串流。 兩個串流的位置依複製的位元組數前進。 |
CopyTo(Stream)
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
從目前串流讀取位元組,然後寫入另一條串流。 兩個串流的位置依複製的位元組數前進。
public:
void CopyTo(System::IO::Stream ^ destination);
public void CopyTo(System.IO.Stream destination);
member this.CopyTo : System.IO.Stream -> unit
Public Sub CopyTo (destination As Stream)
參數
- destination
- Stream
將當前串流內容複製到的串流。
例外狀況
destination 是 null。
要麼是目前的串流,要麼 destination 在方法被呼叫前 CopyTo(Stream) 就已關閉。
發生 I/O 錯誤。
範例
以下範例將 a 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());
' Create the streams.
Dim destination As New MemoryStream()
Using source As FileStream = File.Open("c:\temp\data.dat", _
FileMode.Open)
Console.WriteLine("Source length: {0}", source.Length.ToString())
' Copy source to destination.
source.CopyTo(destination)
End Using
Console.WriteLine("Destination length: {0}", destination.Length.ToString())
備註
複製從目前串流的當前位置開始,且在複製操作完成後不會重置目的串流的位置。
適用於
CopyTo(Stream, Int32)
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
- 來源:
- Stream.cs
從目前串流讀取位元組,並依指定緩衝區大小寫入另一串流。 兩個串流的位置依複製的位元組數前進。
public:
void CopyTo(System::IO::Stream ^ destination, int bufferSize);
public:
virtual void CopyTo(System::IO::Stream ^ destination, int bufferSize);
public void CopyTo(System.IO.Stream destination, int bufferSize);
public virtual void CopyTo(System.IO.Stream destination, int bufferSize);
member this.CopyTo : System.IO.Stream * int -> unit
abstract member CopyTo : System.IO.Stream * int -> unit
override this.CopyTo : System.IO.Stream * int -> unit
Public Sub CopyTo (destination As Stream, bufferSize As Integer)
Public Overridable Sub CopyTo (destination As Stream, bufferSize As Integer)
參數
- destination
- Stream
將當前串流內容複製到的串流。
- bufferSize
- Int32
緩衝區的大小。 此值必須大於零。 預設大小是 81920。
例外狀況
destination 是 null。
bufferSize 為負數或零。
要麼是目前的串流,要麼 destination 在方法被呼叫前 CopyTo(Stream) 就已關閉。
發生 I/O 錯誤。
備註
複製從目前串流的當前位置開始,且在複製操作完成後不會重置目的串流的位置。