Here you can find the source of saveDocument(Document doc, File f)
public static void saveDocument(Document doc, File f) throws TransformerException, IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { private static Transformer transformer; public static void saveDocument(Document doc, File f) throws TransformerException, IOException { f.getParentFile().mkdirs();/*from ww w. j a v a 2 s. com*/ FileWriter writer = new FileWriter(f); transformer.transform(new DOMSource(doc), new StreamResult(writer)); writer.close(); } }