The format of data in the database file is as follows:
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block
Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
End of file
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
n bytes (defined by previous entry), field name
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
so you just have to read that many bytes into an array of bytes. Then convert them into a String.
When you read the bytes into the byte array, you probably want to ensure that you do read fully all the bytes that form the name (as opposed to potentially only reading some of the bytes.
Regards, Richard
SCJP 1.2, SCWCD, SCBCD
can't resolve symbol
Regards, Richard
fieldName=String(name,"UTF-8");
"UTF-8" is not "US-ASCII" though it could still get correct result from your db.db file.
All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
Regards, Richard
Regards, Richard
How can I work out header length
How can I work out [...] record [...] length?
How can I work out [...] record count?
Next step,how can I continue to get each record?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
You now know where the data starts, and how big it is.
Regards, Richard
I think that I have already read the file header and schema info.But I dont ensure that's true or not.
Also I dont know the place where data starts...
In order to finish Data class well,I should read all the records step by step.
Have you had some ways to solve that?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Regards, Richard
Regards, Richard
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|