transformer.transform(..正在抛出IO异常/找不到文件异常

时间:2015-05-05 09:09:17

标签: java ioexception

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无法识别路径。

还有什么原因?

1 个答案:

答案 0 :(得分:1)

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

StreamResult result = new StreamResult(ewFile); 到StreamResult result = new StreamResult(ewFile.getPath());

并且有效。

相关问题