You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System.IO/FileStream.xml
+24-26Lines changed: 24 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -4076,6 +4076,7 @@ If the write operation is successful, the position within the file stream advanc
4076
4076
4077
4077
]]></format>
4078
4078
</remarks>
4079
+
<exceptioncref="T:System.IO.IOException">.NET 8 and later versions: The underlying pipe is closed or disconnected.</exception>
4079
4080
</Docs>
4080
4081
</Member>
4081
4082
<MemberMemberName="Write">
@@ -4141,19 +4142,18 @@ If the write operation is successful, the position within the file stream advanc
4141
4142
<remarks>
4142
4143
<formattype="text/markdown"><![CDATA[
4143
4144
4144
-
## Remarks
4145
-
This method overrides <xref:System.IO.Stream.Write%2A>.
4145
+
## Remarks
4146
+
4147
+
This method overrides <xref:System.IO.Stream.Write%2A>.
4146
4148
4147
-
The `offset` parameter gives the offset of the byte in `array` (the buffer index) at which to begin copying, and the `count` parameter gives the number of bytes that will be written to the stream. If the write operation is successful, the current position of the stream is advanced by the number of bytes written. If an exception occurs, the current position of the stream is unchanged.
4149
+
The `offset` parameter gives the offset of the byte in `array` (the buffer index) at which to begin copying, and the `count` parameter gives the number of bytes that will be written to the stream. If the write operation is successful, the current position of the stream is advanced by the number of bytes written. If an exception occurs, the current position of the stream is unchanged.
4148
4150
4149
4151
> [!NOTE]
4150
-
> Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite%2A>.
4152
+
> Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite%2A>.
4151
4153
4152
-
Do not interrupt a thread that is performing a write operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.
4154
+
Do not interrupt a thread that's performing a write operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.
4153
4155
4154
-
For a list of common file and directory operations, see [Common I/O Tasks](/dotnet/standard/io/common-i-o-tasks).
4155
-
4156
-
4156
+
For a list of common file and directory operations, see [Common I/O Tasks](/dotnet/standard/io/common-i-o-tasks).
4157
4157
4158
4158
## Examples
4159
4159
This code example is part of a larger example provided for the <xref:System.IO.FileStream.Lock%2A> method.
@@ -4174,12 +4174,16 @@ If the write operation is successful, the position within the file stream advanc
4174
4174
4175
4175
-or-
4176
4176
4177
-
Another thread may have caused an unexpected change in the position of the operating system's file handle.</exception>
4177
+
Another thread may have caused an unexpected change in the position of the operating system's file handle.
4178
+
4179
+
-or-
4180
+
4181
+
.NET 8 and later versions: The underlying pipe is closed or disconnected.</exception>
4178
4182
<exceptioncref="T:System.ObjectDisposedException">The stream is closed.</exception>
4179
4183
<exceptioncref="T:System.NotSupportedException">The current stream instance does not support writing.</exception>
4180
-
<relatedtype="Article"href="/dotnet/standard/io/">File and Stream I/O</related>
4181
-
<relatedtype="Article"href="/dotnet/standard/io/how-to-read-text-from-a-file">How to: Read Text from a File</related>
4182
-
<relatedtype="Article"href="/dotnet/standard/io/how-to-write-text-to-a-file">How to: Write Text to a File</related>
4184
+
<relatedtype="Article"href="/dotnet/standard/io/">File and stream I/O</related>
4185
+
<relatedtype="Article"href="/dotnet/standard/io/how-to-read-text-from-a-file">How to: Read text from a file</related>
4186
+
<relatedtype="Article"href="/dotnet/standard/io/how-to-write-text-to-a-file">How to: Write text to a file</related>
4183
4187
</Docs>
4184
4188
</Member>
4185
4189
<MemberMemberName="WriteAsync">
@@ -4224,7 +4228,7 @@ If the write operation is successful, the position within the file stream advanc
4224
4228
4225
4229
## Remarks
4226
4230
4227
-
The `WriteAsync` method lets you perform resource-intensive I/O operations without blocking the main thread. This performance consideration is particularly important in a Windows 8.x Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. The async methods are used in conjunction with the `async` and `await` keywords in Visual Basic and C#.
4231
+
The `WriteAsync` method lets you perform resource-intensive I/O operations without blocking the main thread. This performance consideration is particularly important in apps where a time-consuming stream operation can block the UI thread and make your app appear as if it isn't working.
4228
4232
4229
4233
Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing.
4230
4234
@@ -4296,21 +4300,19 @@ If the operation is canceled before it completes, the returned task contains the
4296
4300
<formattype="text/markdown"><![CDATA[
4297
4301
4298
4302
## Remarks
4299
-
The <xref:System.IO.FileStream.WriteAsync%2A> method enables you to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a Windows 8.x Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. The async methods are used in conjunction with the `async` and `await` keywords in Visual Basic and C#.
4303
+
The <xref:System.IO.FileStream.WriteAsync%2A> method enables you to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in apps where a time-consuming stream operation can block the UI thread and make your app appear as if it isn't working.
4300
4304
4301
4305
Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing.
4302
4306
4303
-
If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status%2A> property. If the handle to the file is disposed, the returned task contains the <xref:System.ObjectDisposedException> exception in the <xref:System.Threading.Tasks.Task.Exception%2A> property.
4304
-
4305
-
4307
+
If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status%2A> property. If the handle to the file is disposed, the returned task contains the <xref:System.ObjectDisposedException> exception in the <xref:System.Threading.Tasks.Task.Exception%2A> property.
4308
+
4309
+
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.IO.FileStream.Write(System.Byte[],System.Int32,System.Int32)>.
4306
4310
4307
4311
## Examples
4308
4312
The following example shows how to write asynchronously to a file.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.IO.FileStream.Write(System.Byte[],System.Int32,System.Int32)>.
<paramrefname="offset" /> or <paramrefname="count" /> is negative.</exception>
4321
4323
<exceptioncref="T:System.ArgumentException">The sum of <paramrefname="offset" /> and <paramrefname="count" /> is larger than the buffer length.</exception>
4322
-
<exceptioncref="T:System.NotSupportedException">The stream does not support writing.</exception>
4323
-
<exceptioncref="T:System.ObjectDisposedException">The stream has been disposed.</exception>
4324
-
<exceptioncref="T:System.InvalidOperationException">The stream is currently in use by a previous write operation.</exception>
@@ -4383,9 +4382,7 @@ If the operation is canceled before it completes, the returned task contains the
4383
4382
Use `WriteByte` to write a byte to a `FileStream` efficiently. If the stream is closed or not writable, an exception will be thrown.
4384
4383
4385
4384
> [!NOTE]
4386
-
> Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite%2A>.
4387
-
4388
-
4385
+
> Use the <xref:System.IO.FileStream.CanWrite%2A> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite%2A>.
4389
4386
4390
4387
## Examples
4391
4388
The following code example shows how to write data to a file, byte by byte, and then verify that the data was written correctly.
@@ -4398,6 +4395,7 @@ If the operation is canceled before it completes, the returned task contains the
4398
4395
</remarks>
4399
4396
<exceptioncref="T:System.ObjectDisposedException">The stream is closed.</exception>
4400
4397
<exceptioncref="T:System.NotSupportedException">The stream does not support writing.</exception>
4398
+
<exceptioncref="T:System.IO.IOException">.NET 8 and later versions: The underlying pipe is closed or disconnected.</exception>
4401
4399
<blocksubset="none"type="overrides">
4402
4400
<para>The default implementation on <seelangword="Stream" /> creates a new single-byte array and then calls <seecref="M:System.IO.Stream.Write(System.Byte[],System.Int32,System.Int32)" />. While this is formally correct, it is inefficient. Any stream with an internal buffer should override this method and provide a much more efficient version that reads the buffer directly, avoiding the extra array allocation on every call.
0 commit comments