import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectInputOutputStream {
public static void main(String[] args) throws IOException, ClassNotFoundException {
//writing object to a file
ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("objout.txt"));
Student s = new Student();
s.setId(100);
s.setName("James Go");
s.setCourse("Information Technology");
s.setAge(18);
oout.writeObject(s);
oout.flush();
//reading object from a file
ObjectInputStream in = new ObjectInputStream(new FileInputStream("objout.txt"));
Student student = (Student) in.readObject();
System.out.println("Student ID :" + s.getId());
System.out.println("Name :" + s.getName());
System.out.println("Age :" + s.getAge());
System.out.println("Course :" + s.getCourse());
}
}
#########################################
import java.io.Serializable;public class Student implements Serializable {
private int id;
private String name;
private String course;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}



