RandomAccessFile read/write start-finish position problem
<p>I've searched this a lot but still can't find... So I hope you can help me to understand :)</p>

<p>The question is...</p>

<p>I have big file A.dat and I want </p>

<ul>
<li>A) Read it with RandomAccessFile (to
avoid OutOfMemory error) </li>
<li>B) Read it by pieces of 4Mb (buffer)</li>
<li>C) Write each this 4Mb piece to file
B.dat</li>
<li>D) So to make file B.dat as a copy of
file A.dat</li>
</ul>

<p>But I have a problem... If I have a file which length cannot be devided by 4Mb the data get lost and file become corrupted :( </p>

<p>For example...
I have media file. Its length is 15.8Mb so I can get only 15.8Mb/4Mb=3 whole pieces. Then I can write only those 3 bytes pieces and the rest get lost :( 
Or the problem is if file is smaller than buffer size (4Mb)... </p>

<p>I think it shouldn't be a hard task but I couldn't see any standart tutorial which shows how to solve such kind of things... </p>

<p>I dearly hope you can help me with this question.</p>

<p>Andrew</p>
