FileChannel.TransferTo(Int64, Int64, IWritableByteChannel) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Transfers bytes from this channel's file to the given writable byte channel.
[Android.Runtime.Register("transferTo", "(JJLjava/nio/channels/WritableByteChannel;)J", "GetTransferTo_JJLjava_nio_channels_WritableByteChannel_Handler")]
public abstract long TransferTo (long position, long count, Java.Nio.Channels.IWritableByteChannel? target);
[<Android.Runtime.Register("transferTo", "(JJLjava/nio/channels/WritableByteChannel;)J", "GetTransferTo_JJLjava_nio_channels_WritableByteChannel_Handler")>]
abstract member TransferTo : int64 * int64 * Java.Nio.Channels.IWritableByteChannel -> int64
Parameters
- position
- Int64
The position within the file at which the transfer is to begin; must be non-negative
- count
- Int64
The maximum number of bytes to be transferred; must be non-negative
- target
- IWritableByteChannel
The target channel
Returns
The number of bytes, possibly zero, that were actually transferred
- Attributes
Exceptions
if the parameters are invalid.
if this channel is not readable.
if the target channel is not writable.
if either channel has already been closed.
if either channel is closed by other threads during this operation.
if the thread is interrupted during this operation.
if any I/O error occurs.
Remarks
Transfers bytes from this channel's file to the given writable byte channel.
An attempt is made to read up to count
bytes starting at the given position
in this channel's file and write them to the target channel. An invocation of this method may or may not transfer all of the requested bytes; whether or not it does so depends upon the natures and states of the channels. Fewer than the requested number of bytes are transferred if this channel's file contains fewer than count
bytes starting at the given position
, or if the target channel is non-blocking and it has fewer than count
bytes free in its output buffer.
This method does not modify this channel's position. If the given position is greater than the file's current size then no bytes are transferred. If the target channel has a position then bytes are written starting at that position and then the position is incremented by the number of bytes written.
This method is potentially much more efficient than a simple loop that reads from this channel and writes to the target channel. Many operating systems can transfer bytes directly from the filesystem cache to the target channel without actually copying them.
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.