Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package serialization;
  2.  
  3. import java.io.*;
  4. import java.io.Serializable;
  5.  
  6. public class SerializationSample {
  7.  
  8.     public static void main(String[] args) throws IOException{
  9.         Student st =new Student(1);
  10.         FileOutputStream fs =new FileOutputStream("student.ser");
  11.         ObjectOutputStream os =new ObjectOutputStream(fs);
  12.         os.writeObject(st);
  13.         os.close();
  14.     }
  15. }
  16.  
  17. class Student implements Serializable{
  18.    
  19.     int id;
  20.    
  21.     public Student(int id){
  22.         this.id = id;
  23.     }
  24. }