write Object to XML String as JavaBean - Java XML

Java examples for XML:XML Java Bean

Description

write Object to XML String as JavaBean

Demo Code


//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();
    }
}

Related Tutorials