Dela via


FileChannel.Write Method

Definition

Overloads

Write(ByteBuffer)

Writes a sequence of bytes to this channel from the given buffer.

Write(ByteBuffer[])

Writes a sequence of bytes to this channel from the given buffers.

Write(ByteBuffer, Int64)

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

Write(ByteBuffer[], Int32, Int32)

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

Write(ByteBuffer)

Writes a sequence of bytes to this channel from the given buffer.

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;)I", "GetWrite_Ljava_nio_ByteBuffer_Handler")]
public abstract int Write (Java.Nio.ByteBuffer? src);
[<Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;)I", "GetWrite_Ljava_nio_ByteBuffer_Handler")>]
abstract member Write : Java.Nio.ByteBuffer -> int

Parameters

src
ByteBuffer

the byte buffer containing the bytes to be written.

Returns

Implements

Attributes

Exceptions

if the channel was not opened for writing.

if the channel was already closed.

if another thread closes the channel during the write.

if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.

if another I/O error occurs, details are in the message.

Remarks

Writes a sequence of bytes to this channel from the given buffer.

Bytes are written starting at this channel's current file position unless the channel is in append mode, in which case the position is first advanced to the end of the file. The file is grown, if necessary, to accommodate the written bytes, and then the file position is updated with the number of bytes actually written. Otherwise this method behaves exactly as specified by the WritableByteChannel interface.

Java documentation for java.nio.channels.FileChannel.write(java.nio.ByteBuffer).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Write(ByteBuffer[])

Writes a sequence of bytes to this channel from the given buffers.

[Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;)J", "")]
public long Write (Java.Nio.ByteBuffer[]? srcs);
[<Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;)J", "")>]
abstract member Write : Java.Nio.ByteBuffer[] -> int64
override this.Write : Java.Nio.ByteBuffer[] -> int64

Parameters

srcs
ByteBuffer[]

Returns

Implements

Attributes

Exceptions

if this channel is closed by another thread during this write operation.

if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.

if this channel is closed.

if another I/O error occurs; details are in the message.

if this channel was not opened for writing.

Remarks

Writes a sequence of bytes to this channel from the given buffers.

Bytes are written starting at this channel's current file position unless the channel is in append mode, in which case the position is first advanced to the end of the file. The file is grown, if necessary, to accommodate the written bytes, and then the file position is updated with the number of bytes actually written. Otherwise this method behaves exactly as specified in the GatheringByteChannel interface.

Java documentation for java.nio.channels.FileChannel.write(java.nio.ByteBuffer[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Write(ByteBuffer, Int64)

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;J)I", "GetWrite_Ljava_nio_ByteBuffer_JHandler")]
public abstract int Write (Java.Nio.ByteBuffer? src, long position);
[<Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;J)I", "GetWrite_Ljava_nio_ByteBuffer_JHandler")>]
abstract member Write : Java.Nio.ByteBuffer * int64 -> int

Parameters

src
ByteBuffer

The buffer from which bytes are to be transferred

position
Int64

The file position at which the transfer is to begin; must be non-negative

Returns

The number of bytes written, possibly zero

Attributes

Exceptions

if position is less than 0.

if this channel is closed.

if the channel was not opened in write-mode.

if this channel is closed by another thread while this method is executing.

if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.

if another I/O error occurs.

Remarks

Writes a sequence of bytes to this channel from the given buffer, starting at the given file position.

This method works in the same manner as the #write(ByteBuffer) method, except that bytes are written starting at the given file position rather than at the channel's current position. This method does not modify this channel's position. If the given position is greater than the file's current size then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

Java documentation for java.nio.channels.FileChannel.write(java.nio.ByteBuffer, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Write(ByteBuffer[], Int32, Int32)

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

[Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;II)J", "GetWrite_arrayLjava_nio_ByteBuffer_IIHandler")]
public abstract long Write (Java.Nio.ByteBuffer[]? srcs, int offset, int length);
[<Android.Runtime.Register("write", "([Ljava/nio/ByteBuffer;II)J", "GetWrite_arrayLjava_nio_ByteBuffer_IIHandler")>]
abstract member Write : Java.Nio.ByteBuffer[] * int * int -> int64

Parameters

srcs
ByteBuffer[]
offset
Int32

the index of the first buffer in buffers to get bytes from.

length
Int32

the number of buffers to get bytes from.

Returns

Implements

Attributes

Exceptions

if this channel is closed by another thread during this write operation.

if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.

if this channel is closed.

if offset or length , or if offset + length is greater than the size of buffers.

if another I/O error occurs; details are in the message.

if this channel was not opened for writing.

Remarks

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

Bytes are written starting at this channel's current file position unless the channel is in append mode, in which case the position is first advanced to the end of the file. The file is grown, if necessary, to accommodate the written bytes, and then the file position is updated with the number of bytes actually written. Otherwise this method behaves exactly as specified in the GatheringByteChannel interface.

Java documentation for java.nio.channels.FileChannel.write(java.nio.ByteBuffer[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to