import java.io.FileWriter; import java.io.IOException; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; public class XMLWriterExample { public static void main(String[] args) { XStream xstream = new XStream(new DomDriver()); Person person = new Person("John", "Doe", 30); String xmlString = xstream.toXML(person); try { XMLWriter writer = new XMLWriter(new FileWriter("person.xml")); writer.write(xmlString); writer.close(); } catch (IOException e) { e.printStackTrace(); } } } class Person { private String firstName; private String lastName; private int age; public Person(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } }


上一篇:
下一篇:
切换中文