java.lang.IndexOutOfBoundsException despite setLength()

Please take a look at the following code:

RandomAccessFile file =new RandomAccessFile("file","rw");// the file didn't exist prior to this instruction

file.setLength(1000);

file.write(buffer, 0, 200);

file.write(buffer, 200, 200);

The first write() works ok but the second one throws java.lang.IndexOutOfBoundsException. Shouldn't it just write another 200 bytes to the file since I've used setLength()?

Thanks.

[573 byte] By [swiergota] at [2007-11-27 5:43:15]
# 1
This says write 200 bytes from the buffer starting at byte zerothen write 200 bytes from the buffer starting at byte 200.The error has nothing to do with the setLength() and everything to do with the fact that you have not declared buffer to have a length of at least
sabre150a at 2007-7-12 15:22:40 > top of Java-index,Core,Core APIs...
# 2
Oh, shoot! Guilty of reading no more than write()'s header. Thanks!
swiergota at 2007-7-12 15:22:40 > top of Java-index,Core,Core APIs...