我试图通过使用 DOM 修改 xml 文件,这发生了:
javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\D:\myproject\build\web\xml\myFile.xml (The filename, directory name, or volume label syntax is incorrect)
at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:263)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:296)
at utils.UpdateUtils.BookUpdate(UpdateUtils.java:36)
这是我的代码
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(f);
searchAndModify(doc); //modify xml's contents
Source source = new DOMSource(doc);
Result result = new StreamResult(f);
TransformerFactory tff = TransformerFactory.newInstance();
Transformer trans = tff.newTransformer();
trans.transform(source, result);
f 是我的 xml,生成的。它解析为 Document doc 就好了。但是,在转换时,会引发异常。
我试图解析到一个新的xml,相同的文件夹,但无济于事:
Result result = new StreamResult(new File(path, "newFile.xml"));
javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\D:\myProject\build\web\newFile.xml (The filename, directory name, or volume label syntax is incorrect)
有人遇到过这个问题或有解决方案吗?请帮我!