开发者

from OutputStream to a File Stream

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜