I'm doing my homework on java I/O data, the problem is i'm not allowed to use object serialization to load data from a binary file.
Here is the assignment requirements:
Persistence, writing objects to file and reading objects from file (Text format)
• All objects should be written to a single file in a text format • All objects should be read form the same file • You should use JFileChooser
I have 3 classes: Unit, Assessment, and Task.
The Assessment class is abstract while IndividualAssessment & GroupAssessment are concrete subclasses.
Unit has a collection of Assessment and Assessment has a collection of Tasks.
I could save all data to one text file with FileWriter but I don't know how to read each line of the text file in to the proper Assessment class.
What I mean is how do you recognize which line is for IndividualAssessment or GroupAssessment classes.
Here is the code I tried but it's not working:
BufferedReader bf = new BufferedReader(file);
While (bf.readLine != null){
Unit u = new Unit(bf);
diary.add(u);
try{
Assessment a = new IndividualAssessment(bf);
} catch (IOException ex){
Assessment a = new GroupAssessment(bf);
}
u.add(a);
Task t = new Task(bf);
a.add(t);
implements Serializable? What about usingXMLEncoder/XMLDecoder?