title: how to efficiently maintain one file with max size limit but appending new to end of the file
body: <p>in an Android app, need to write some data to a file. And the file cannot over the max size. If it reaches the max size it should remove top/old data and append new data to the file (like rolling up).</p>
  
  <p>It could be done by read in the file and remove same amount of data as the new one to be appended to make space for the new data to be written/appended. But it is not efficient since every time it needs to read in whole file to do the cut and write back.</p>
  
  <p>If using two files to rotate it may lost some data. I.e. when both files are full, then delete one file to start from beginning, some of the old data are lost.</p>
  
  <p>Anyone has suggestion to do it efficiently?</p>