当前位置: 技术问答>java相关
关于xml转换的问题!!!
来源: 互联网 发布时间:2015-09-08
本文导语: 为什么我用DOM解析的xml文件,在用 StreamResult result=new StreamResult(System.out); transformer.transform(sourcedoc,result);时能正常显示xml文件在屏幕上,而改为StreamResult result=new StreamResult("t.txt");或 StreamResult result=new StreamResult("t...
为什么我用DOM解析的xml文件,在用
StreamResult result=new StreamResult(System.out);
transformer.transform(sourcedoc,result);时能正常显示xml文件在屏幕上,而改为StreamResult result=new StreamResult("t.txt");或
StreamResult result=new StreamResult("t.xml");时却不能,这是什么原因?还要进行其它的处理吗?
StreamResult result=new StreamResult(System.out);
transformer.transform(sourcedoc,result);时能正常显示xml文件在屏幕上,而改为StreamResult result=new StreamResult("t.txt");或
StreamResult result=new StreamResult("t.xml");时却不能,这是什么原因?还要进行其它的处理吗?
|
如果是字符串参数的话,必须是URL格式的。。。。。。。
或者用:
StreamResult(java.io.File f)来接收文件类型的参数。
所以你应该:
StreamResult result=new StreamResult(new File("t.txt"));
没有加路径的话,就是你运行命令的目录下的文件。
或者用:
StreamResult(java.io.File f)来接收文件类型的参数。
所以你应该:
StreamResult result=new StreamResult(new File("t.txt"));
没有加路径的话,就是你运行命令的目录下的文件。
|
当然你还可以用
StreamResult result=new StreamResult(new FileOutputStream("t.txt"));
StreamResult result=new StreamResult(new FileOutputStream("t.txt"));
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。