2014-02-20 27 views
0

通常使用时...使用jar文件xmlparserv2.jar时,如果文件路径有空格,则转换a不起作用。我怎样才能解决这个问题?

Transformer t = TransformerFactory.newInstance().newTransformer(); 
t.transform(source,result); 

(不xmlparserv2.jar文件)的文件未发现异常看起来是这样的。

Exception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings\username\nonExistentFile.xml (The system cannot find the file specified) 

当包括xmlparserv2.jar,异常变成这个

Caused by: java.io.FileNotFoundException: C:\Documents%20and%20Settings\username\existingFile.xml (The system cannot find the path specified) 

的文件实际上是有(变换方法找到它时,我不包括JAR),但是当我包括jar,由于为空格插入%20,转换方法无法找到它。有人能告诉我如何解决这个问题吗?

回答

0

对不起,应该包括更多的代码...答案是在结果对象我被进入。此外,

最初它看起来像这样

File f = new File(filePath); 
Result result = new StreamResult(f); 

改变这个..

File f = new File(filePath); 
StreamResult result = new StreamResult(); 
FileOutputStream fos = new FileOutputStream(f); 
result.setOutputStream(fos); 
相关问题