import java.io.*;
class Student implements Serializable{
int id;
String name;
int age;
String department;
public Student(int id,String name,int age,String department){
this.id=id;
this.name=name;
this.age=age;
this.department=department;
}
}
public class Objectser implements Serializable{
public static void main(String args[]){
Student stu=new Student(703034138,"sunwxb",23,"CP");
try{
FileOutputStream fo=new FileOutputStream("data.ser");
ObjectOutputStream so=new ObjectOutputStream(fo);
so.writeObject(stu);
so.close();
}catch(Exception e){
System.out.println(e);
}
}
}
import java.io.*;
class Student implements Serializable{
int id;
String name;
int age;
String department;
public Student(int id,String name,int age,String department){
this.id=id;
this.name=name;
this.age=age;
this.department=department;
}
}
public class ObjectRecov Serializable{
public static void main(String args[]) {
Student stu;
try{
FileInputStream fi=new FileInputStream("data.ser");
ObjectInputStream si=new ObjectInputStream(fi);
stu=(Student)si.readObject();
si.close();
}catch(Exception e){
System.out.println(e);
}
System.out.println("ID:" +stu.id +"name:" +stu.name +"age" +stu.age +"dept:" +stu.department);
}
}