I am trying the AsynchronousFileChannel
JAVA 7 API to write a file in an async manner, however I could not find an easy way to append to the file.
The API description states that AsynchronousFileChannel
doesn't maintain the file position and you have to specify the file position. This means that you have to maintain a global file position value. Moreover this global state should be atomic so that you are correctly incrementing.
Is there a better way of doing updates using the AsynchronousFileChannel
?
Also, can someone please explain the use of the Attachment object in the API?
public abstract <A> void write(ByteBuffer src,
long position,
A attachment,
CompletionHandler<Integer ,? super A> handler)
The javadoc says: attachment - The object to attach to the I/O operation; can be null
What is the use of this attachment object?
Thanks!