XML Transform results in FileNotFoundException

若如初见. 提交于 2019-12-07 18:12:41

问题


The earlier question I posted is closed because of lack of information.
Please let me know if I am missing something here. The transformer seems to be adding file:/ to the beginning of my file path.

I am working in a Solaris environment, and here is what happens when the transform gets applied:

DOMSource sourcexml = new DOMSource(doc);
StreamResult resultxml = new StreamResult(new File("file.xml"));
transformer.transform(sourcexml, resultxml); 

The exception I get is:

javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:/opt/origenate/or_dev87/apps/documentarchive/file.xml (No such file or directory)

Note, the file exists in /opt/origenate/or_dev87/apps/documentarchive/file.xml, but the transformer object is looking for file:/opt/origenate/or_dev87/apps/documentarchive/file.xml.

Why does it append the file:/? Is there anyway I can remove it?


回答1:


Try to execute below code:

DOMSource sourcexml = new DOMSource(doc);
StreamResult resultxml = new StreamResult(new File("file.xml").getAbsolutePath());
transformer.transform(sourcexml, resultxml); 


来源:https://stackoverflow.com/questions/15432145/xml-transform-results-in-filenotfoundexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!