Java Reference
In-Depth Information
transferTo(long position,
Attempts to transfer
count
bytes from this
channel to the channel,
dst
. Bytes are
read from this channel starting at the file
position specified by
position
. The
position of this channel is not altered by
this operation but the position of
dst
will
be incremented by the number of bytes
written. Fewer than
count
bytes will be
transferred if this channel's file has fewer
than
count
bytes remaining, or if
dst
is
non-blocking and has fewer than
count
bytes free in its system output buffer. The
number of bytes transferred is returned as
type
int
.
long count,
WritableByteChannel dst)
transferFrom(ReadableByteChannel
src,
long
position,
long
count)
Attempts to transfer
count
bytes to this
channel from the channel
src
. Bytes are
written to this channel starting at the file
position specified by
position
. The
position of this channel is not altered by
the operation but the position of
src
will
be incremented by the number of bytes
read from it. If
position
is
greater
than
the size of the file, then no bytes will be
transferred. Fewer than
count
bytes will
be transferred if the file corresponding to
src
has fewer than count bytes remaining
in the file or if it is non-blocking and has
fewer than
count
bytes free in its system
input buffer. The number of bytes
transferred is returned as type
int
.
A channel that was obtained from a
FileInputStream
object will only support the
transferTo()
method. Similarly, a channel that was obtained from a
FileOutputStream
object will only support the
transferFrom()
method. Both of these methods can throw any of the following flurry of exceptions:
IllegalArgumentException
Thrown if either count or position is negative.
NonReadableChannelException
Thrown if the operation attempts to read from a channel
that was not opened for reading.
NonWritableChannelException
Thrown if the operation attempts to write to a channel
that was not opened for writing.
ClosedChannelException
Thrown if either channel involved in the operation is
closed.
Table continued on following page