Export (0) Print
Expand All

FileStream::Write Method

Writes a block of bytes to the file stream.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual void Write(
	array<unsigned char>^ array, 
	int offset, 
	int count
) override

Parameters

array
Type: array<System::Byte>

The buffer containing data to write to the stream.

offset
Type: System::Int32

The zero-based byte offset in array from which to begin copying bytes to the stream.

count
Type: System::Int32

The maximum number of bytes to write.

ExceptionCondition
ArgumentNullException

array is nullptr.

ArgumentException

offset and count describe an invalid range in array.

ArgumentOutOfRangeException

offset or count is negative.

IOException

An I/O error occurred.

- or -

Another thread may have caused an unexpected change in the position of the operating system's file handle.

ObjectDisposedException

The stream is closed.

NotSupportedException

The current stream instance does not support writing.

This method overrides Write.

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.

NoteNote

Use the CanWrite property to determine whether the current instance supports writing. For additional information, see CanWrite.

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.

For a list of common file and directory operations, see Common I/O Tasks.

This code example is part of a larger example provided for the Lock method.

// Write the original file data. 
if ( fileStream->Length == 0 )
{
   tempString = String::Concat( lastRecordText, recordNumber.ToString() );
   fileStream->Write( uniEncoding->GetBytes( tempString ), 0, uniEncoding->GetByteCount( tempString ) );
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft