4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
My data accessing code :
Is this right?What should i modify?Thank you for your response.
[ July 17, 2005: Message edited by: Shengzhi Peng ]
[Andrew: put code between [code] and [/code] UBB tags]
[ July 17, 2005: Message edited by: Andrew Monkhouse ]
you should really try to use descriptive names for your variables. For example
As Barry mentioned, using readUTF (at least in the way you are using it) is probably not correct. Take a look at the API documentation for readUTF - how does this method know the amount of data to read?
FieldInfo field = null;
File file =new File("db-2x1.db");
RandomAccessFile db = new RandomAccessFile(file,"rw");
int magicCookie = db.readInt();
int recordSize = db.readInt();
int numberOfFields = db.readShort();
for(int i = 0; i < s3; i++)
int fieldLength = db.readShort();
field[i] = new FieldInfo(db.readUTF(),db.readShort);
Like this, OK?But how to use fieldLength to influence the readUTF()?
May i know what method i should use? Thank you !
Please make sure that code you are posting will at least compile, otherwise I get the feeling you are asking me to do your research for you.
From the API documentation for readUTF:
So the readUTF method itself reads the size of the field - you should not be doing this within your program.
The first two bytes are read, starting from the current file pointer, as if by readUnsignedShort. This value gives the number of following bytes that are in the encoded string, not the length of the resulting string. The following bytes are then interpreted as bytes encoding characters in the UTF-8 format and are converted into characters.
Thank you for your response.I really don't how to search the record from the file.This have stopped me two days to write the code.Maybe you will think if you told me how to do.I will not think it myself,it is not good for me.But i think the answer will not stop me to think it myself.I just want to know the basic way to do so.And i will turn the knowledge to myself.