正常情况下使用......
Transformer t = TransformerFactory.newInstance().newTransformer();
t.transform(source,result);
(没有xmlparserv2.jar文件)一个File Not Found Exception看起来像这样。
Exception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings\username\nonExistentFile.xml (The system cannot find the file specified)
当你包含xmlparserv2.jar时,Exception会转到这个
Caused by: java.io.FileNotFoundException: C:\Documents%20and%20Settings\username\existingFile.xml (The system cannot find the path specified)
该文件实际上存在(当我不包含jar时,transform方法找到它)但是当我包含jar时,由于为空白插入了%20,转换方法无法找到它。有人可以告诉我如何解决这个问题吗?
答案 0 :(得分:0)
抱歉,应该包含更多代码......答案在我传入的结果对象中。
原来看起来像这样
File f = new File(filePath);
Result result = new StreamResult(f);
改为此..
File f = new File(filePath);
StreamResult result = new StreamResult();
FileOutputStream fos = new FileOutputStream(f);
result.setOutputStream(fos);