import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root public class Book { @Element private String name; @Element private String author; @Element private double price; } import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; public class Main { public static void main(String[] args) throws Exception { Book book = new Book(); book.setAuthor("Bruce Eckel"); book.setPrice(59.99); Serializer serializer = new Persister(); serializer.write(book, new File("book.xml")); Book newBook = serializer.read(Book.class, new File("book.xml")); } }


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