Here you can find the source of writeDocument(Document document, File file)
public static void writeDocument(Document document, File file) throws TransformerException
//package com.java2s; //it under the terms of the GNU Affero General public static License as published by import java.io.File; import java.io.OutputStream; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; 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 writeDocument(Document document, File file) throws TransformerException { TransformerFactory transformFactory = TransformerFactory.newInstance(); Transformer idTransform = transformFactory.newTransformer(); Source input = new DOMSource(document); Result output = new StreamResult(file); idTransform.transform(input, output); }/*from ww w. j a v a2 s .c om*/ public static void writeDocument(Document document, OutputStream out) throws TransformerException { TransformerFactory transformFactory = TransformerFactory.newInstance(); Transformer idTransform = transformFactory.newTransformer(); Source input = new DOMSource(document); Result output = new StreamResult(out); idTransform.transform(input, output); } }