1

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 Answers1

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