繁体   English   中英

从OutputStream到文件流

[英]from OutputStream to a File Stream

我想将DOM文档另存为XML文件。 我遵循此教程: http : //java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html

所以,这是我的代码:

...
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);

但是我想将结果保存在文件中,而不是System.out 我怎样才能做到这一点?

采用

new StreamResult(new FileOutputStream(...))

但是,您可能要使用Writer ,以便输出编码的字符,除非StreamResult隐式使用Unicode编码(例如UTF-8)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM