Hi..

I want to write the "Person" object to the "phone.dat " file but i have a problem while reading..

class Person
{
int i;

public Person(int i)
{
this.i = i;
}
}


File file = new File("phone.dat");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file,true)); //true = append mode
Person myClass = new Person( 5 ); //my number 5
oos.writeObject(myClass);
oos.close


I write this code and it performed successfully. Another time , i want to append another "Person" object. Also this was successfull (The file size increased succesfully)

File file = new File("phone.dat");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file,true)); //true = append mode
Person myClass = new Person( 17 ); //my number 17
oos.writeObject(myClass);
oos.close

But when i want to read the objects from the file:

File file = new File("phone.dat");
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
Person class1= (Person )ois.readObject();
Person class2= (Person )ois.readObject();

System.out.println ( class1.i ); //prints "5"
System.out.println( class2.i ); //nothing prints...

ois.close;



Could you explain why i can't read the second object? I have a project so this is very important for me..

Thank you very much.