Here you can find the source of saveDocument(Document doc, File file)
public static void saveDocument(Document doc, File file) throws TransformerConfigurationException, TransformerException
//package com.java2s; import java.io.File; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { public static void saveDocument(Document doc, String xmlPath) throws TransformerConfigurationException, TransformerException { saveDocument(doc, new File(xmlPath)); }//from ww w. j a va 2s . c o m public static void saveDocument(Document doc, File file) throws TransformerConfigurationException, TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(file); transformer.transform(source, result); } }