Java Reference
In-Depth Information
Current Buffer Position
Current Buffer Limit
Byte Buffer
data is written starting with the byte at the
at the point
buffers position
the position
specified by
File
Current File Position
The file channel object maintains a record of the current position in the file. If the file stream was created to
append to the file by using a FileOutputStream constructor with the append mode argument as true ,
then the file position recorded by the channel for the file will start out at the byte following the last byte.
Otherwise, the initial file position will be the first byte of the file. The file position will generally be
incremented by the number of bytes written each time you write to the file. There is one exception to this.
The FileChannel class defines a special write() method that does the following:
Method
Description
write(ByteBuffer buf, long
position)
This writes the buffer, buf , to the file at
the position specified by the second
argument, and not the file position
recorded by the channel. Bytes from the
buffer are written starting at the buffer's
current position, and
buf.remaining() bytes will be
written. This does not update the
channel's file position.
This method can throw any of the following exceptions:
Exception
Description
IllegalArgumentException
Thrown if you specify a negative value for the
file position.
NonWritableChannelException
Thrown if the file was not opened for writing.
Table continued on following page
Search WWH ::




Custom Search