Hi, I have a program that writes to and reads from a random access file. That is, it's trying to...
The program loops around (it has a menu that runs in a loop until user chooses to quit), and one of the operations is to read from the file what is in there. The file contains records of an ADT I have developed, but when the method returns objects representing each of these records, instead of outputting the String, the int and the double that I know is saved in the file for each record, it outputs the name of the data type of each record, along with some garble starting with an @sign. Does this look familiar to anyone?
I want the method to return the contents of one record to the driver program , but instead what is output from the driver program (using the toString() method on the object passed as a parameter) is something along the lines of: basicRecord@130c19b.
You need to override the toString() method in your basicRecord class. What you are seeing is the output from the Object.toString() method.
Joined: May 12, 2004
Hi, I followed your advice and it now returns the data in the record. Thanks!
However, there is a new problem now, in that one of the fields is a String variable. Since I wanted fixed length records, I have a method in the basic record class that "pads out" the String so that it fills the fixed length. When the data in the Record object is returned (using the overridden toString method), it displays the empty bytes as well (they look like little squares).
I'll include the relevant methods in a simplified example:
The following method in the driver program steps through each record sequentially (I know, why sequentially? Will write a hashing algorithm for direct access next):
How can I ensure that the readRecord method only returns those bytes in the String that contain actual characters, and not the unsightly little sqares?