Java examples for XML:XML Java Bean
Object Xml Encoder using Java Bean XML Encoder
//package com.java2s; import java.beans.XMLEncoder; import java.io.File; import java.io.FileOutputStream; public class Main { public static void main(String[] argv) throws Exception { Object obj = "java2s.com"; String fileName = "java2s.com"; ObjectXmlEncoder(obj, fileName); }//w w w.j ava2s . c o m public static void ObjectXmlEncoder(Object obj, String fileName) { // File fo = new File(fileName); // if (!fo.exists()) { // String path = fileName.substring(0, fileName.lastIndexOf('.')); File pFile = new File(path); pFile.mkdirs(); } try { // FileOutputStream fos = new FileOutputStream(fo); // XML XMLEncoder encoder = new XMLEncoder(fos); // XML encoder.writeObject(obj); encoder.flush(); // encoder.close(); // fos.close(); } catch (Exception e) { // TODO: handle exception } } }