I have successfully created an object in a file using ObjectOutputStream but when i try to read that obj it gives an exception. Please help I am unable to handle this::java.io.EOFException
public class ObjInputObjOutput {
public static void main(String[] args) {
FileInputStream fs;
ObjectInputStream os;
try{
fs=new FileInputStream("C:\\Users\\MYPC\\Desktop\\temp.txt");
os=new ObjectInputStream(fs);
os.readObject();
Student s=(Student) os.readObject();
s.toString();
}catch(Exception e){System.out.println(e);}
}
}
class Student implements Serializable
{
int rno;
String add;
float cgpa;
String name;
public Student(int rno, String add, float cgpa, String name) {
this.rno = rno;
this.add = add;
this.cgpa = cgpa;
this.name = name;
}
public String toString()
{
return "Roll no:"+rno+"\n"+"Add"+add+"\n"+"Cgpa"+cgpa+"\n"+"Name"+name;
}
}