This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am writing some data to a file via a fileChannel and I want to make sure that it fits neatly on the disk block size so the disk does not end up doing the read,copy, write routine to fill sectors that are only half used. I am writing 4KB blocks which are the same size as the disks 4096 byte sectors so when I write each block it will fit nicely in a sector and not get split into two pieces.
The file will start at the beginning of a block I presume so I should be able to get everything aligned by making sure that everything is a multiple of 4096 bytes including padding free space with zeros so every write is 4KB.
At the beginning of the file do I write the first block from 0 to 4095 or from 1 to 4096? I need this info because I will be performing random 4k writes in other areas of the file and I need to make sure it all lines up with blocks on the disk ie. block 1 =0-4095 block 2 =4096-8191 block 3 =8192-12287 etc. or block 1 =1-4096 block 2 =4097-8192 block 3= 8193-12288 etc.
The filechannel API only says I can use any non negative integer for the position parameter so I would assume that it starts from 0.