Stream.Write Metoda
Definicja
Przeciążenia
Write(ReadOnlySpan<Byte>) |
Gdy jest zastępowany w klasie pochodnej, zapisuje sekwencję bajtów do bieżącego strumienia i zwiększa bieżącą pozycję w tym strumieniu o liczbę zapisanych bajtów.When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. |
Write(Byte[], Int32, Int32) |
Gdy jest zastępowany w klasie pochodnej, zapisuje sekwencję bajtów do bieżącego strumienia i zwiększa bieżącą pozycję w tym strumieniu o liczbę zapisanych bajtów.When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. |
Write(ReadOnlySpan<Byte>)
Gdy jest zastępowany w klasie pochodnej, zapisuje sekwencję bajtów do bieżącego strumienia i zwiększa bieżącą pozycję w tym strumieniu o liczbę zapisanych bajtów.When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public:
virtual void Write(ReadOnlySpan<System::Byte> buffer);
public virtual void Write (ReadOnlySpan<byte> buffer);
abstract member Write : ReadOnlySpan<byte> -> unit
override this.Write : ReadOnlySpan<byte> -> unit
Public Overridable Sub Write (buffer As ReadOnlySpan(Of Byte))
Parametry
- buffer
- ReadOnlySpan<Byte>
Region pamięci.A region of memory. Ta metoda kopiuje zawartość tego regionu do bieżącego strumienia.This method copies the contents of this region to the current stream.
Uwagi
Użyj CanWrite właściwości, aby określić, czy bieżące wystąpienie obsługuje zapisywanie.Use the CanWrite property to determine whether the current instance supports writing. Użyj WriteAsync metody, aby zapisać asynchronicznie w bieżącym strumieniu.Use the WriteAsync method to write asynchronously to the current stream.
Jeśli operacja zapisu powiedzie się, pozycja w strumieniu zastąpi przez liczbę zapisanych bajtów.If the write operation is successful, the position within the stream advances by the number of bytes written. Jeśli wystąpi wyjątek, pozycja w strumieniu pozostaje niezmieniona.If an exception occurs, the position within the stream remains unchanged.
Dotyczy
Write(Byte[], Int32, Int32)
Gdy jest zastępowany w klasie pochodnej, zapisuje sekwencję bajtów do bieżącego strumienia i zwiększa bieżącą pozycję w tym strumieniu o liczbę zapisanych bajtów.When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public:
abstract void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public abstract void Write (byte[] buffer, int offset, int count);
abstract member Write : byte[] * int * int -> unit
Public MustOverride Sub Write (buffer As Byte(), offset As Integer, count As Integer)
Parametry
- buffer
- Byte[]
Tablica bajtów.An array of bytes. Ta metoda kopiuje count
bajty z buffer
do bieżącego strumienia.This method copies count
bytes from buffer
to the current stream.
- offset
- Int32
Przesunięcie bajtu (liczony od zera), w buffer
którym rozpocznie się kopiowanie bajtów do bieżącego strumienia.The zero-based byte offset in buffer
at which to begin copying bytes to the current stream.
- count
- Int32
Liczba bajtów do zapisania w bieżącym strumieniu.The number of bytes to be written to the current stream.
Wyjątki
Suma offset
i count
jest większa niż długość buforu.The sum of offset
and count
is greater than the buffer length.
buffer
to null
.buffer
is null
.
offset
lub count
jest ujemna.offset
or count
is negative.
Wystąpił błąd we/wy, na przykład nie można znaleźć określonego pliku.An I/O error occurred, such as the specified file cannot be found.
Strumień nie obsługuje zapisu.The stream does not support writing.
Write(Byte[], Int32, Int32) został wywołany po zamknięciu strumienia.Write(Byte[], Int32, Int32) was called after the stream was closed.
Uwagi
Użyj CanWrite właściwości, aby określić, czy bieżące wystąpienie obsługuje zapisywanie.Use the CanWrite property to determine whether the current instance supports writing. Użyj WriteAsync metody, aby zapisać asynchronicznie w bieżącym strumieniu.Use the WriteAsync method to write asynchronously to the current stream.
Jeśli operacja zapisu powiedzie się, pozycja w strumieniu zastąpi przez liczbę zapisanych bajtów.If the write operation is successful, the position within the stream advances by the number of bytes written. Jeśli wystąpi wyjątek, pozycja w strumieniu pozostaje niezmieniona.If an exception occurs, the position within the stream remains unchanged.
Zobacz też
- We/Wy plików i strumieniFile and Stream I/O
- Instrukcje: Odczytywanie tekstu z plikuHow to: Read Text from a File
- Instrukcje: Zapisywanie tekstu w plikuHow to: Write Text to a File