Monday, March 10, 2014

Serialize Object to XML file in java

XStream xstream=new XStream();
EvaluationResult ae=new EvaluationResult();
FileOutputStream fileOut =new FileOutputStream("result.txt");
ObjectOutputStream out = xstream.createObjectOutputStream(fileOut);

out.writeObject(ae);
out.close();
fileOut.close();

FileInputStream inputStream = new FileInputStream("result.txt");
ObjectInputStream in = xstream.createObjectInputStream(inputStream);
EvaluationResult be=(EvaluationResult)in.readObject();


Tutorial:
http://xstream.codehaus.org/objectstream.html

Need:(download jar file from the url above)
xstream-1.4.7.jar
kxml2-2.3.0.jar
kxml2-min-2.3.0.jar

No comments:

Post a Comment