Paul Lutus said:
This is called a fixed-field-width database. I hope the data are not all on
one long line as you show it.
*sigh*
Why not? It's, like you said, a fixed field width database. Lines are
irrelevant.
Given the "schema" you presented, you have records that are 32 (25 + 7)
bytes (crass assumption, but realistic) long.
So, to read a record from this file, you would open a RandomAccessFile,
calculate the offset using the record length, RandomAccessFile.seek() to
that position, and then read record length bytes into a byte array used as a
record buffer.
Finally, you'd break the record buffer up into fields with which you'd do
with what you please.
Crude example:
public byte[] readRecord(int recordNum)
{
RandomAccessFile f = new RandomAccessFile("file.dat");
long recordLength = 25 + 7;
byte recordBuffer = new byte[recordLength];
long recordOffset = recordNum * recordLength;
f.seek(recordOffset);
f.read(recordBuffer);
f.close();
return recordBuffer;
}
Making this efficient and robust is left as an additional homework
assignment on top of this one.
Regards,
Will Hartung
(
[email protected])