0

SampleClass.java and keywords.properties are present in this location in my system :
/home/user/Projects/SampleProject/src/main/java/com/package/subPackage/

SampleClass.java have both static and non-static functions.
In static function ClassLoader.getSystemResourceAsStream(FILE_PATH)
In non-static function this.getClass().getClassLoader().getResourceAsStream(FILE_PATH)

But It returns null in InputStream.I tried every possible combination for FILE_PATH like this :

/home/user/Projects/SampleProject/src/main/java/com/package/subPackage/prefix.properties

src/main/java/com/package/subPackage/prefix.properties

com/package/subPackage/prefix.properties

prefix.properties

I followed these links
getResourceAsStream() vs FileInputStream
http://viralpatel.net/blogs/loading-java-properties-files/

Nothing worked for me . Please suggest me where am I doing wrong?

Community
  • 1
  • 1
Badman
  • 407
  • 5
  • 17

1 Answers1

1

besides that resources should be put in the resources folder and not in main source, try /com/package/subPackage/prefix.properties

Emerson Cod
  • 1,990
  • 3
  • 21
  • 39
  • I tried you suggestion FILE_PATH = "/com/package/subPackage/prefix.properties" but It didn't work .But resource folder thing worked for me. In my project there is already resources folder.I created a config folder and added prefix.properties (new location : /home/user/Projects/SampleProject/src/resources/config/prefix.properties).Updated FILE_PATH = "config/prefix.properties" and it worked .Thanks – Badman Jan 30 '17 at 13:35
  • do you have a maven project ? I assumed by the path you gave.... then the resource files should be in `src/main/resources/` – Emerson Cod Jan 30 '17 at 13:42
  • Yeah It's Maven and you are right resources in that folder path "src/main/resources/" – Badman Jan 30 '17 at 14:00