Java XML Document Save to File saveDoc(Document doc, OutputStream output)

Here you can find the source of saveDoc(Document doc, OutputStream output)

Description

save Doc

License

Open Source License

Declaration

public static void saveDoc(Document doc, OutputStream output) throws TransformerException 

Method Source Code

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

Related

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