문제

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