2012-04-04 37 views
1

我正在使用Play Framework 2.0。在我的一個測試用例中,我想讀取一些XML/HTML文件的內容。我試着:如何在Play Framework 2.0中加載XML/HTML資源

getClass().getResource("SomeFile.xml");

getClass().getResourceAsStream("SomeFile.xml");

,但我得到一個空。資源與我的測試用例在同一個包中。 enter image description here

回答

1

也許你可以試試這個方法:

/** 
* Retrieves a resource stream from the classpath. 
* 
* @param relativePath relative path of the resource to fetch 
* @return InputStream to the resource (may be null) 
*/ 
play.Play.application().resourceAsStream(String resourceName) 
+0

對我來說,工作方式相同的getClass()的getResourceAsStream。 – kolen 2013-02-01 13:20:17