0
我需要從戰爭中獲取屬性文件。無法從戰爭中獲取文件
String fileName = loadFileName();
try {
FileInputStream fis = new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource(fileName).toURI()));
property.load(fis);
}
.........
private String loadFileName(){
if(currentLocale.equals(new Locale("en"))){
return "file:///locale/output/language.properties";
} else {
return "file:///locale/output/language_ru.properties";
}
}
此文件位於main/resources/locale/output文件夾中。不幸的是,這種方法不起作用,所有的屬性值都是空的。如何正確加載戰爭文件?服務器:JBoss應用服務器7
如果資源位於正確位置,請直接使用'getResourceAsStream(fileName)'讀取'InputStream'。 –
查看您的代碼,您可能會發現使用[ResourceBundle](http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html)更容易。 –
@SotiriosDelimanolis它沒有幫助。也許我的路線錯了?我添加完整路徑的圖片。 –