Hi All,
I am trying to load from a .dat file a collection of student objects
However on load it only loads the first student and then stops
I've tried to put print messages in but with all the nulls I really can't seem to work out what is happening.
I see the first student added without problems, it's just nothing after that works.
If I add a new one before closing the program, I can see it added to the array
and when I save, it increases the .dat file size so that seems to be working without
a problem. Just not sure why it isn't returning an array > 1 student?
Could anyone please assist, thank you in advance!
The IO method is as follows:
public student[] loadStudent() throws IOException, ClassNotFoundException
//loads the accounts and returns them
{
ObjectInputStream fileInput = new ObjectInputStream(new FileInputStream("allstudents.dat"));
student[] returnStudent = new student[MAX_STUDENTS];
try
{
for (int i = 0; i < MAX_STUDENTS; i ++)
{
returnStudent[i] = (student)fileInput.readObject();
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
fileInput.close();
}
return returnStudent;
}
The code that calls it and saves to the array is
public void loadStudent() throws IOException, ClassNotFoundException
//loads the accounts from a file
{
unistudent = memory.loadStudent();
int loader = MAX_STUDENTS; //makes the loop happen the right amount of times
for (int i = 0; i < loader ; i ++)
{
if (unistudent[i] != null)
{
currentStudent++;
}
else
{
loader--;
}
}
}