Here you can find the source of writeDocToFile(Document doc, String fileName)
Parameter | Description |
---|---|
doc | the doc |
fileName | the file name |
Parameter | Description |
---|---|
Exception | the exception |
public static void writeDocToFile(Document doc, String fileName) throws Exception
//package com.java2s; import org.w3c.dom.Document; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.File; import java.io.FileOutputStream; public class Main { /**/*from ww w .j a v a 2 s. co m*/ * ***************************************** * Output Document to file * ******************************************. * * @param doc the doc * @param fileName the file name * @throws Exception the exception */ public static void writeDocToFile(Document doc, String fileName) throws Exception { File encryptionFile = new File("c:\\temp\\" + fileName); FileOutputStream f = new FileOutputStream(encryptionFile); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(f); transformer.transform(source, result); f.close(); } }