Java:将StreamResult保存到文件 [英] Java: Saving StreamResult to a file
本文介绍了Java:将StreamResult保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SAX进行一些数据转换(例如csv)到xml,然后在Java中使用转换器.结果在StreamResult中,我试图将结果保存到file.xml中,但是找不到将StreamResult保存到文件中的方法.我做错了吗?
I am doing some data conversion(like csv) to xml with SAX then using transformer in Java. The result is in StreamResult, and I am trying to save this result to a file.xml but I can't find way to save StreamResult into file. am I doing this all wrong?
推荐答案
您的StreamResult
应该基于文件创建,例如
Your StreamResult
should be created on the basis of a file, e.g.
StreamResult sr = new StreamResult(new File("/my/file.xml"));
如果给Transformer
这样的StreamResult
,它将把结果直接写到您指定的文件中.
If you give your Transformer
such a StreamResult
, it will write its result directly into the file you specified.
这篇关于Java:将StreamResult保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文