title: best way to write series of objects to a .ser file using ObjectOutputStream and read them back
body: <p>I create series of objects out of Student Class and store them in a vector. I write each object in to a .ser file once it created. Then I read them back. My code is working perfectly. What I want to know is, the way I do this is correct or are there any easy and optimized ways to get this done?? And also how to replace or delete specific object in a .ser file without re-witting whole the file again.</p>
  
  <p>Student Class</p>
  
  <pre><code>public class Student implements Comparable&lt;Student&gt;, Serializable{
  
      private String firstName = "";
      private int registrationNumber;
      private int coursework1;
      private int coursework2;
      private int finalExam;
      private double moduleMark;
  
      public String getFirstName() {
          return firstName;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      public int getRegistrationNumber() {
          return registrationNumber;
      }
      public void setRegistrationNumber(int registrationNumber) {
          this.registrationNumber = registrationNumber;
      }
      public int getCoursework1() {
          return coursework1;
      }
      public void setCoursework1(int coursework1) {
          this.coursework1 = coursework1;
      }
      public int getCoursework2() {
          return coursework2;
      }
      public void setCoursework2(int coursework2) {
          this.coursework2 = coursework2;
      }
      public int getFinalExam() {
          return finalExam;
      }
      public void setFinalExam(int finalExam) {
          this.finalExam = finalExam;
      }
      public double getModuleMark() {
          return moduleMark;
      }
      public void setModuleMark(double moduleMark) {
          this.moduleMark = moduleMark;
      }
      public int compareTo(Student s){
          if (this.moduleMark &gt; s.moduleMark)
              return 1;
          else if (this.moduleMark == s.moduleMark)
              return 0;
          else 
              return -1;
      }
  } 
  </code></pre>
  
  <p>File writing part</p>
  
  <pre><code>public static void Write(Student mm){
          try
            {
              FileOutputStream fileOut = new FileOutputStream("info.ser",true);
              ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fileOut));
  
              out.writeObject(mm);            
              out.close();
              fileOut.close();
              System.out.println("Serialized data is saved in info.ser");
            }catch(IOException i)
            {
                //i.printStackTrace();
            }
  
      }
  </code></pre>
  
  <p>Reading part </p>
  
  <pre><code>public static int Read() {
          int count=0;
          try{
              vector = new Vector&lt;Student&gt;();
              FileInputStream saveFile = new FileInputStream("info.ser");
              ObjectInputStream save;
              try{
                  for(;;){
                      save = new ObjectInputStream(saveFile);
                      student = (Student) save.readObject();
                      vector.add(student);
                      count++;
                  }
              }catch(EOFException e){
                  //e.printStackTrace();
              }
              saveFile.close(); 
  
          }catch(Exception exc){
              exc.printStackTrace();
          }
          return count;
      }
  </code></pre>