Java examples for XML:XML Java Bean
write Object to XML String as JavaBean
//package com.java2s; import java.beans.XMLEncoder; import java.io.BufferedOutputStream; import java.io.FileOutputStream; public class Main { public static void main(String[] argv) throws Exception { Object obj = "java2s.com"; String filename = "java2s.com"; write(obj, filename);//from www. java 2 s .c o m } public static void write(Object obj, String filename) throws Exception { XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream( new FileOutputStream(filename))); encoder.writeObject(obj); encoder.close(); } }