Writes from Object to xml file. - Java XML

Java examples for XML:JAXB

Description

Writes from Object to xml file.

Demo Code


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main{
    public static void main(String[] argv) throws Exception{
        String path = "java2s.com";
        Object obj = "java2s.com";
        write(path,obj);// w w w .j av a 2  s  .  co  m
    }
    /**
     * Writes from Object to xml file.
     * 
     * @param xml
     *            path to xml file
     * @param obj
     *            JAXB object
     * @throws FileNotFoundException
     *             if file is not existing
     */
    public static void write(String path, Object obj)
            throws FileNotFoundException {

        OutputStream os = new FileOutputStream(path);
        XmlParser.marshal(obj, os);

    }
}

Related Tutorials