Advertisement
m1o2

ClassSerializationIO

Sep 23rd, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.ObjectInputStream;
  6. import java.io.ObjectOutputStream;
  7. import java.io.Serializable;
  8.  
  9.  
  10. public class ClassSerializationIO {
  11.  
  12.     public static Object readObject( String objectName ) throws FileNotFoundException, IOException, ClassNotFoundException{
  13.        
  14.         ObjectInputStream in = new ObjectInputStream( new FileInputStream( objectName ) );
  15.        
  16.         return in.readObject();
  17.     }
  18.    
  19.     public static void writeObject( Serializable obj, String name ) throws FileNotFoundException, IOException{
  20.        
  21.         ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( name ) );
  22.        
  23.         out.writeObject( obj );
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement