Here you can find the source of saveDoc(Document doc, OutputStream output)
public static void saveDoc(Document doc, OutputStream output) throws TransformerException
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; 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 { private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); public static void saveDoc(Document doc, OutputStream output) throws TransformerException { try {/*from w w w . j a va2 s.co m*/ Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); transformer.transform(new DOMSource(doc), new StreamResult(output)); } finally { try { output.close(); } catch (IOException e) { // } } } public static void saveDoc(Document doc, File file) throws IOException, TransformerException { file.getParentFile().mkdirs(); saveDoc(doc, new FileOutputStream(file)); } }