Code example for ObjectInputStream

Methods: close, readObject

0
			FileInputStream fis = new FileInputStream("serial1"); // creating a stream to read obj1
			FileInputStream fis1 = new FileInputStream("serial2");// creating a stream to read obj2
			 
			ObjectInputStream ois = new ObjectInputStream(fis); 
			obj1 = (MyClass)ois.readObject();  // reading and casting the saved obj1
			ois = new ObjectInputStream(fis1);
			obj2 = (MyClass)ois.readObject();// reading and casting the saved obj2
			ois.close(); 
			 
			System.out.println("object1: " + obj1);
			System.out.println("object2: " + obj2);
		}  
		 
		catch(Exception e) { 
			System.out.println("Exception during deserialization: " + e); 
			System.exit(0); 
		}  
	}  
}