// Write Student objects to file

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class StudentWrite {
    public static void main(String[] args) throws Exception {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File("student.ser")));
  
        Student st1 = new Student();
        st1.setRollNo(1102107L);
        st1.setName("Abhishek Bhatia");
        st1.setCourse("BCA");
      
        Student st2 = new Student();
        st2.setRollNo(1102108L);
        st2.setName("Anushi Kumra");
        st2.setCourse("BCA");
      
        Student st3 = new Student();
        st3.setRollNo(1102110L);
        st3.setName("Bhanu Pratap Singh");
        st3.setCourse("BCA");
      
        out.writeObject(st1);
        out.writeObject(st2);
        out.writeObject(st3);
      
        out.close();
    }
}

Comments

Popular posts from this blog

Zeller's Congruence

Property Event-Delegation

Method with variable arguments