0

通常使用時...

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

(xmlparserv2.jar ファイルがない場合) File Not Found Exception は次のようになります。

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のために変換メソッドがファイルを見つけることができません。誰かがこれを修正する方法を教えてもらえますか?

4

1 に答える 1

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);
于 2014-02-20T18:39:45.217 に答える