开发者

from OutputStream to a File Stream

开发者 https://www.devze.com 2023-01-03 08:24 出处:网络
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

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);
StreamResu开发者_开发技巧lt 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号