title: java.io.StreamCorruptedException: In java Code
body: <p>How to read the object in to the file i am use the ObjectInputStream and ObjectOutputStream
  class to read and write the Object of the my custom class Student for this demo.</p>
  
  <p>Code to Write and read use::</p>
  
  <pre><code>            try
              {
                  if(af.filepath==null || af.filepath=="")//file path
                  {
                      JOptionPane.showMessageDialog(null, "Please Set File Path", "File Path Error", JOptionPane.ERROR_MESSAGE);
                  }
                  else
                  {
                      FileOutputStream fs=new FileOutputStream(af.filepath,true);
                      ObjectOutputStream fo=new ObjectOutputStream(fs);   
                      fo.writeObject(af.s);//write the Super Class Object
                      fo.close();
                  }
  
              }
              catch (Exception ex)
              {
                      System.out.println(ex);
              }
  
     ---------------------------------------------------------------------------------
          try
          {
              if(af.filepath==null || af.filepath=="")//file path have whole path of the file
              {
                  JOptionPane.showMessageDialog(null, "Please Set File Path", "File Path Error", JOptionPane.ERROR_MESSAGE);
              }
              else
              {
                  Student sp;
                  FileInputStream fs=new FileInputStream(af.filepath);
                  ObjectInputStream fo=new ObjectInputStream(fs);
                  while ((sp=(Student)fo.readObject())!=null) 
                  {
                      sp.set();//for print object
                  }
                  fo.close();
              }
  
          }
          catch (Exception ex)
          {
                  ex.printStackTrace();
          }
  </code></pre>
  
  <p>using this i am read first object in the file but after that raise an error</p>