Stream.CopyTo Metodo
Definizione
Legge i byte dal flusso corrente e li scrive in un altro flusso.Reads the bytes from the current stream and writes them to another stream.
Overload
CopyTo(Stream) |
Legge i byte dal flusso corrente e li scrive in un altro flusso.Reads the bytes from the current stream and writes them to another stream. |
CopyTo(Stream, Int32) |
Legge tutti i byte dal flusso corrente e li scrive in un altro flusso, usando una dimensione di buffer specificata.Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. |
CopyTo(Stream)
Legge i byte dal flusso corrente e li scrive in un altro flusso.Reads the bytes from the current stream and writes them to another stream.
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)
Parametri
- destination
- Stream
Flusso in cui verrà copiato il contenuto del flusso corrente.The stream to which the contents of the current stream will be copied.
Eccezioni
destination
è null
.destination
is null
.
Il flusso corrente non supporta la lettura.The current stream does not support reading.
-oppure--or-
destination
non supporta la scrittura.destination
does not support writing.
Il flusso corrente o destination
sono stati chiusi prima che venisse chiamato il metodo CopyTo(Stream).Either the current stream or destination
were closed before the CopyTo(Stream) method was called.
Si è verificato un errore di I/O.An I/O error occurred.
Esempio
Nell'esempio seguente viene copiato il contenuto di un oggetto FileStream in un oggetto MemoryStream .The following example copies the contents of a FileStream to a 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())
Commenti
La copia inizia in corrispondenza della posizione corrente nel flusso corrente e non reimposta la posizione del flusso di destinazione al termine dell'operazione di copia.Copying begins at the current position in the current stream, and does not reset the position of the destination stream after the copy operation is complete.
Si applica a
CopyTo(Stream, Int32)
Legge tutti i byte dal flusso corrente e li scrive in un altro flusso, usando una dimensione di buffer specificata.Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.
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)
Parametri
- destination
- Stream
Flusso in cui verrà copiato il contenuto del flusso corrente.The stream to which the contents of the current stream will be copied.
- bufferSize
- Int32
Dimensione del buffer.The size of the buffer. Il valore deve essere maggiore di zero.This value must be greater than zero. La dimensione predefinita è 81920.The default size is 81920.
Eccezioni
destination
è null
.destination
is null
.
bufferSize
è un valore negativo o zero.bufferSize
is negative or zero.
Il flusso corrente non supporta la lettura.The current stream does not support reading.
-oppure--or-
destination
non supporta la scrittura.destination
does not support writing.
Il flusso corrente o destination
sono stati chiusi prima che venisse chiamato il metodo CopyTo(Stream).Either the current stream or destination
were closed before the CopyTo(Stream) method was called.
Si è verificato un errore di I/O.An I/O error occurred.
Commenti
La copia inizia in corrispondenza della posizione corrente nel flusso corrente e non reimposta la posizione del flusso di destinazione al termine dell'operazione di copia.Copying begins at the current position in the current stream, and does not reset the position of the destination stream after the copy operation is complete.