[英]resourcebundle vs properties
Hi I have a problem loading Properties to Java. 嗨,我在将属性加载到Java时遇到问题。
ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
Loads a file from main source folder. 从主源文件夹加载文件。
while 而
InputStream in = ThisClass.class.getClass().getResourceAsStream(propertiesFileName);
properties.load(in);
loads a file from main project folder, which is outside classpath. 从类路径之外的主项目文件夹中加载文件。 For now it is unclear how to load properties from source folder as well. 现在还不清楚如何从源文件夹中加载属性。
I don't want propertiesFileName to have /src/
in it because it won't work from jar then. 我不希望propertyFileName在其中包含/src/
,因为那样将无法从jar中运行。 Could it be relater to my IDE, I use Netbeans. 可能与我的IDE有关,我使用Netbeans。
I had this problem recently! 我最近有这个问题!
try: 尝试:
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFileName);
properties.load(in);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.