Java XML JAXB Serialize serializeToXmlFile(T object, String fileName)

Here you can find the source of serializeToXmlFile(T object, String fileName)

Description

serialize To Xml File

License

Open Source License

Declaration

public static <T> void serializeToXmlFile(T object, String fileName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class Main {
    public static <T> void serializeToXmlFile(T object, String fileName) {
        try {//from  w w  w.  ja  v a2  s.co  m
            JAXBContext context = JAXBContext.newInstance(object.getClass());
            try (FileOutputStream outStream = new FileOutputStream(fileName)) {
                context.createMarshaller().marshal(object, outStream);
            }
        } catch (JAXBException | IOException e) {
        }
    }
}

Related

  1. serializeFile(String path, Object o)
  2. serializeToFile(Class clazz, T object, String outputFile)
  3. serializeToSTD(Object obj)
  4. serializeToString(Object obj)
  5. serializeToString(Object obj)
  6. xmlSerialize(String filename, T obj)