As Peter Lawrey mentioned, you need to call cbuff.flip()
between the read and write. It seems that the append will read from the position of the buffer, which is at the end if we don't call cbuff.flip()
. The reason why a part from somewhere in the middle is still written is because in the end, the buffer won't be completely filled, thus some "old" bytes will still be between the position in the buffer and the end of the buffer.
Mystery solved :-)
Read full article from java - Reading a file into a CharBuffer, then a StringBuilder or StringBuffer seems to leave out on parts of the file. Why? - Stack Overflow
No comments:
Post a Comment