Reputation: 466
I want to save my DOM Document as an XML file. I follow this tutorial: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html
So, this is my code:
...
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
but instead of System.out, I want to save in a file the result. How can I do this?
Upvotes: 0
Views: 1056
Reputation: 64026
Use
new StreamResult(new FileOutputStream(...))
But you may want to use a Writer
, so that you are outputting encoded characters, unless StreamResult
is using a Unicode encoding, say UTF-8, implicitly.
Upvotes: 3