JAXB marshalling Java to output XML file JAXB marshalling Java to output XML file xml xml

JAXB marshalling Java to output XML file


If you are using a JAXB 2.1 or greater then you can marshal directly to a java.io.File object:

 File file = new File( "nosferatu.xml" ); marshaller.marshal( quickXML, file );

Corrsponding Javadoc


You are already marshalling to nosferatu.xml. Just remove or comment the line:

marshaller.marshal(quickXML, System.out);

if you don't wish to display the output and close the OutputStream:

os.close();


Marshaller#marshall(...) method takes an OutputStream or Writer as parameter. Surely you would have found this in the API if you had looked.