DOMSource source = new DOMSource(document);
                ewFile = barcoUtil.getEwFile(Ew_Thread.ewLogger);
                StreamResult result = new StreamResult(ewFile);
                System.out.println("Ok I have came here--->"+ewFile.getAbsolutePath());
                transformer.transform(source, result);


它生成FileNotFoundException

Ok I have came here--->F:\Barco\employwise-barco files\EW_2015-05-05 14-35-55.txt
javax.xml.transform.TransformerException: java.io.FileNotFoundException: F:\Barco\employwise-barco%20files\EW_2015-05-05%2014-35-55.txt (The system cannot find the path specified)
    at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:297)


但是文件已经存在。

我唯一的怀疑,因为抛出异常的URL包含%20而不是空格,这可能是Windows无法识别路径。

还有什么可能是原因?

最佳答案

解决了问题昨天,问题在于包含%20作为空格的路径。我改变

StreamResult结果=新的StreamResult(ewFile);
StreamResult result = new StreamResult(ewFile.getPath());

而且有效。

关于java - Transformer.transform(..引发IO异常/找不到文件异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30048666/

10-09 21:47