How do I read a property file present in another package with Resource Bundle?

2.1k views Asked by At

User file location Property File locationI have a property file in one package named EnotebookCore, but I have to read it in another package named User in one of its java file. When the property file was in one other folder of the same package i.e. User, I gave the full path of the property file in java file(present in another folder)and it was working fine. But now I am supposed to shift property file to a new package and I am unable to read it from there.

1

There are 1 answers

4
Lucian On

When you say

ResourceBundle.getBundle("com.sial.enotebook.user.languages.‌​user", Locale.US);

Java will look in the package com.sial.enotebook.user.languages for a bundle called user. More exactly it will look in the folder com/sial/enotebook/user/languages for a property file named user_US.properties or user.properties

In your case, make sure that the .properties file is named correctly (including case) and sits in the correct package. For example, if the bundle name is Messages (capital M) and sits in the com.sial.enotebook package, you need to have a Messages.properties file in the com/sial/enotebook folder and use the following:

ResourceBundle.getBundle("com.sial.enotebook.Messages", Locale.US);