Serializing and De-serializing a Java object to XML
Posted by zone817A Java object can be serialized as XML using the XMLEncoder
try { XMLEncoder enc= new XMLEncoder(new BufferedOutputStream( new FileOutputStream("<output xml file>"))); enc.writeObject(instance);//instance is the bean object to be serialized enc.close(); } catch (FileNotFoundException e) { }
De-serializing the XML file can be done as follows using the XMLDecoder
Read more »
try { XMLDecoder dec= new XMLDecoder(new BufferedInputStream( new FileInputStream("<input xml file>"))); MyClass o = (MyClass)dec.readObject(); dec.close(); } catch (FileNotFoundException e) { }
0 comments:
Post a Comment