Write Java Object to XML using Java Bean XML Encoder - Android XML

Android examples for XML:JAXB

Description

Write Java Object to XML using Java Bean XML Encoder

Demo Code


//package com.java2s;

import java.beans.XMLEncoder;
import java.io.*;

public class Main {
    public static void main(String[] argv) throws Exception {
        String filename = "java2s.com";
        Object obj = "java2s.com";
        Write(filename, obj);//from  w  w w.  j a va  2 s  . c  om
    }

    public static void Write(String filename, Object obj)
            throws FileNotFoundException {
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
                new FileOutputStream(filename)));
        encoder.writeObject(obj);
        encoder.close();
    }
}

Related Tutorials