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.
Asked
Active
Viewed 2,069 times
1
-
Please, post the code you are using – Bruno Jan 04 '17 at 13:38
-
When the file was in a folder in User package, i could read it from one folder languages to other folder bean in userBean , java file by the following code : ResourceBundle bundle = ResourceBundle.getBundle("com.sial.enotebook.user.languages.user", Locale.US); – Phalguni Vatsa Jan 04 '17 at 13:42
-
Is it a property file or a class? – Bruno Jan 04 '17 at 13:44
-
it is a property file – Phalguni Vatsa Jan 04 '17 at 13:47
-
Post the folder structure, please...the class package and the properties location – Bruno Jan 04 '17 at 13:52
-
@BrunoDM I have added links in my question for properties and file location – Phalguni Vatsa Jan 04 '17 at 14:27
1 Answers
0
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);

Lucian
- 181
- 1
- 5
-
Thank you ! But this is working for me. In my current project I need the files location to be from it's class path. – Phalguni Vatsa Jan 04 '17 at 14:24
-
The file is always read from the classpath. You have to create the correct package structure (i.e. folder structure) on your classpath. If you place your .properties file in the same folder as your .java class, then it will sit in the same package as the class. – Lucian Jan 04 '17 at 14:30
-
can you please check the links I have provided in my question for folder structure – Phalguni Vatsa Jan 04 '17 at 14:53
-
Try to put it in the resources folder, i.e. resources/com/sial/enotebook/languages/user.properties. Otherwise, it's possible that it doesn't get copied to the output folder. – Lucian Jan 04 '17 at 15:42