Hi all, have a question regarding the writing of records into the database file.
The instruction states that 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.
However from what I observed in the database file, the text values fields are not null terminated, instead they are padded with spaces.
So now I have two choices now, one is to pad with spaces for each field when its less than its maximum length, or null terminate it.
Which method is more appropriate? Padding with spaces makes the subsequent created records more consistent with existing records. But instruction states that they should be null terminated.
Any advice is greatly appreciated!
SCJP | SCJD | SCWCD | SCBCD | SCEA
Joined: Oct 24, 2007
I followed Sun's example and add extra spaces to fill the fields. This allows my read method to be simpler, because I don't have to check for null characters and can simply read a fixed amount of bytes all at once. Furthermore, it does not violate the requirements, because all fields are full and thus no null characters are needed.
There is, however, one design issue that you should mention if you take this approach. You assume that the data file that came with the assignment will always be padded with spaces and no null characters. In theory, Sun could use another file that does include null characters, because they stated this in the requirements, and that would break my code.
SCJA (94%)<br />SCJP (84%)<br />SCWCD (84%)
Zeng Wei Chu
Joined: Dec 05, 2007
Hi David, thanks for clarifying my doubt. I will stick with the method to pad with spaces. Will add this into my assumptions list.