transformer.transform(.. 抛出 IO exception/File 未找到异常

transformer.transform(.. is throwing an IO exception/File not found exception

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 结果 = new StreamResult(ewFile); 至 StreamResult result = new StreamResult(ewFile.getPath());

成功了。