I'm trying out the random access file function right now, but seem to be having a problem appending a new 'record' to the file. The problem arises when I try to 'pad' up the data I am appending, so that it makes up the required length for ta record.
For some strange reason, if I just append the first two, its ok, the writing to UTF is done perfectly to file. However, once the third is written, the file goes all over the place, fails to take into account the \n character.
Anyone know how to fix this?
Many thx.
Maldini
Code:
RandomAccessFile rf = new RandomAccessFile(data, "rw");
rf.seek(rf.length());
rf.writeUTF("message here it is"+"\n");
String space = pad(" ",15);
String res = space.concat("abc");
rf.seek(rf.length());
rf.writeUTF(res+"\n");
rf.seek(rf.length());
rf.writeUTF(res+"\n");
public static String pad(String p, int n)
{
if (n > 1) return(p+pad(p,--n));
return(p);
}
For some strange reason, if I just append the first two, its ok, the writing to UTF is done perfectly to file. However, once the third is written, the file goes all over the place, fails to take into account the \n character.
Anyone know how to fix this?
Many thx.
Maldini