2010-03-19 81 views
0

我正在使用此代碼生成內容文件。處理XSLT轉換期間的WrappedRuntimeException

try { 
     StreamResult result = new StreamResult(); 
     TransformerFactory tf = TransformerFactory.newInstance(); 
     Templates templ = tf.newTemplates(xsltSource); 
     Transformer transf = templ.newTransformer(); 
     for (String item: groups){ 
      item = item.replaceAll(" ", "-").toLowerCase(); 
      result.setOutputStream(new FileOutputStream(path+item+".html")); 
      transf.clearParameters(); 
      transf.setParameter("group", item); 
      transf.transform(xmlSource, result); 
     } 
    } catch (TransformerConfigurationException e) { 
    throw new SinkException(e.getMessage()); 
    } catch (TransformerException e) { 
    throw new SinkException(e.getMessage()); 
    } 

但在第二次迭代我有一個例外

ERROR: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Read error 

水溼明白是什麼原因?

+0

Templates對象只需要創建一次。嘗試將其移出循環。 – 2010-03-19 18:32:43

+0

它沒有幫助。任何其他想法? – Artic 2010-03-19 19:01:12

+0

爲什麼不添加更多的代碼行?和異常期間報告Stacktrace? – 2010-03-19 19:18:33

回答

1

非常感謝您的幫助。 Th錯誤未正確關閉源資源。 那句話:

Source xmlSource = new StreamSource(new FileInputStream(path+Constants.MANIFEST_FILE_NAME)); 

修正:

Source xmlSource = new StreamSource(path+Constants.MANIFEST_FILE_NAME); 
+2

這就是爲什麼我要求更多的代碼。看到這個位從最初的帖子丟失。該片段顯然沒有錯誤,並且沒有簡單的方法可以猜測在此之前會有什麼後綴。 – 2010-03-19 19:40:07