FileStream.Write(Byte[], Int32, Int32) FileStream.Write(Byte[], Int32, Int32) FileStream.Write(Byte[], Int32, Int32) FileStream.Write(Byte[], Int32, Int32) Method

Definition

Writes a block of bytes to the file stream.

public:
 override void Write(cli::array <System::Byte> ^ array, int offset, int count);
public override void Write (byte[] array, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (array As Byte(), offset As Integer, count As Integer)
Parameters
array
Byte[]

The buffer containing data to write to the stream.

offset
Int32 Int32 Int32 Int32

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

count
Int32 Int32 Int32 Int32

The maximum number of bytes to write.

Exceptions

offset and count describe an invalid range in array.

An I/O error occurred.

- or -

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

The current stream instance does not support writing.

Examples

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 ) );
}

// Write the original file data.
if(fileStream.Length == 0)
{
    tempString = 
        lastRecordText + recordNumber.ToString();
    fileStream.Write(uniEncoding.GetBytes(tempString), 
        0, uniEncoding.GetByteCount(tempString));
}
' Write the original file data.
If aFileStream.Length = 0 Then
    tempString = _
        lastRecordText + recordNumber.ToString()
    aFileStream.Write(uniEncoding.GetBytes(tempString), _
        0, uniEncoding.GetByteCount(tempString))
End If

Remarks

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.

Note

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.

Applies to

See Also