use RandomAccessFile. reduce file open/close