lallous said:
I was trying to write something small and simple, just to complete my
assignment.
Finally, I resorted to using such structure:
class Entry implements Serializable
{
public String s1;
public String s2;
public int id;
}
Then storing lots of entries inside a Vector (which is also serializable)
then using ObjectInput/OutputStream to write/read the whole Vector.
Okay.
Btw, does 'Entry' have to implement Serializable? Or just because every
member inside it is serializable then the whole class would be serializable?
Yes, the class has to be serializable.
The implementation of the java.io.Serializable interface indicates your
*intent* that the data encapsulated by that class should be
serializable... meaning that it's generally independent of location. To
take an obvious example, an object that encapsulates a native file
descriptor number should not be declared to be Serializable, even though
its only field may be an int, which can be easily serialized. The
reason is that the file descriptor number is only meaningful in the
context of this process, so serializing that data to a file or network
stream would be pointless.
Guess this method is okay unless there are inherent problems that can't be
seen by a newbie?!
Nothing I'd classify as a "problem" per se. There are disadvantages of
course; but any approach you choose will have disadvantages. In this
case, the disadvantages are that the data file will be a little larger
than is absolutely necessary, it won't be easily readable by a human
being (e.g., if you're debugging and want to see what data was written
out), and it won't be very compatible with other applications (e.g.,
getting the data into an Excel spreadsheet or an SQL database is much
harder than it would be from a CSV file).
If you don't need any of that, I'd just go for it and not look back.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation