Code example for ObjectOutputStream

Methods: closeflushwriteObject

0
 
	public void testReadWriteObject() throws IOException, ClassNotFoundException { 
		VMID vmid = new VMID(); 
 
		File tmpFile = File.createTempFile("VMIDTest", "tmp"); 
		ObjectOutputStream output = new ObjectOutputStream( 
				new FileOutputStream(tmpFile)); 
		output.writeObject(vmid); 
		output.flush(); 
		output.close(); 
 
		VMID vmid2 = null; 
		ObjectInputStream input = new ObjectInputStream(new FileInputStream( 
				tmpFile)); 
		vmid2 = (VMID) input.readObject(); 
		input.close(); 
		tmpFile.delete(); 
 
		assertTrue(vmid.equals(vmid2)); 
	}