1
我想爲我的自定義螞蟻任務打開源文件。我認爲這很容易,因爲類加載器獲取資源肯定會立即爲我找到源文件。錯誤!閱讀自定義螞蟻任務的源文件
這裏是我的代碼:
//build the name of the template
StringBuilder sb = new StringBuilder(VersionTemplate.class.getName());
sb.append(".java");
String templateName = sb.toString();
//find the template
InputStream inputStream = VersionTemplate.class.getResourceAsStream(templateName);
InputStream爲總是空。
任何想法?
這沒有改變。使用絕對路徑是什麼意思?難道我構建模板名稱的方式不會返回類加載器可訪問的文件嗎? – Thom
看看源代碼。你應該需要的一切都在那裏。 – Thom
對不起,我忽略了。 **我在嘗試自己後更新了答案**。這是行得通的。請試試你的結局。 –