簡體   English   中英

Transformer.transform(..引發IO異常/找不到文件異常

[英]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結果=新的StreamResult(ewFile); StreamResult result = new StreamResult(ewFile.getPath());

而且有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM