質問

Hi I have a problem loading Properties to 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. Could it be relater to my IDE, I use Netbeans.

役に立ちましたか?

解決

I had this problem recently!

try:

        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFileName);
    properties.load(in);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top