Java XML Document Save to File saveDocument(Document doc, File f)

Here you can find the source of saveDocument(Document doc, File f)

Description

save Document

License

Open Source License

Declaration

public static void saveDocument(Document doc, File f) throws TransformerException, IOException 

Method Source Code


//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();
    }
}

Related

  1. save(final String path, final Document xml)
  2. save(String filename, Document document)
  3. saveDoc(Document doc, OutputStream output)
  4. saveDoc(Document doc, String fileName)
  5. saveDocAsXML(Document doc, String filename)
  6. saveDocument(Document doc, File file)
  7. saveDocument(Document doc, File file)
  8. saveDocument(Document doc, String fullFileName)
  9. saveDocument(Document doc, Writer w)