1
對於名稱爲「資源」的文件夾而不是其他名稱,有什麼魔力。我在'資源'中有一個文件,當我嘗試加載它時,它工作正常。Java資源文件夾名稱與某些其他名稱
ClassLoader loader=Thread.currentThread().getContextClassLoader();
InputStream propFile=loader.getResourceAsStream("KCBSEvents/resource/build.properties");
我做一個prop.load(propFile)來加載屬性。
當我嘗試使用類似的邏輯從名爲'Images'的目錄加載圖像時,它失敗。這兩個目錄在我的樹中都處於同一級別。
ClassLoader loader=Thread.currentThread().getContextClassLoader();
java.net.URL logoURL=loader.getClass().getResource("KCBSEvents/Images/KCBSLogo.jpg");
結果是'logoURL'爲空。我只能得出結論,或者有關於目錄名稱'resource'或'getResource'的一些魔術與'getResourceAsStream'不同。有人可以解釋發生了什麼嗎? TIA。
那麼,獲取資源作爲流返回一個流,但可能相關:http://stackoverflow.com/questions/6608795/what-is-the-difference-between-class-getresource-and-classloader-getresource –
也許你應該把圖像文件夾放在資源文件夾中? –
你想要什麼,一個URL或? –