Chris Mowbray
Chris Mowbray

Reputation: 295

cannot locate properties file in java path

My code cannot locate the .properties file where i have stored login information.

I have put the file in the src folder to make sure it compiles, and it does correctly.

below is the current location of the file and how i am trying to access it.

I have tried various different paths but no luck.

enter image description here

Upvotes: 0

Views: 628

Answers (5)

Sai Ye Yan Naing Aye
Sai Ye Yan Naing Aye

Reputation: 6740

Change your code;

 ResourceBundle bundle = ResourceBundle.getBundle("Selenium/readme");

to

 ResourceBundle bundle = ResourceBundle.getBundle("readme");

Upvotes: 1

Metalhead
Metalhead

Reputation: 1449

I see that the .properties file is not inside the src folder. Also check the build path of your project.It will show you the src folders and the output folders location. Once you build the project using eclipse build project option, make sure your properties file is now available in the output folder.

Upvotes: 0

Ahiel
Ahiel

Reputation: 503

you can use this.getClass().getResourceAsStream("readme.properties");

for more information read:

Upvotes: 0

Nandkumar Tekale
Nandkumar Tekale

Reputation: 16158

Read properties file like:

ResourceBundle.getBundle("src/properties/readme.properties"); //Or simply "properties/readme.properties"

Put readme.properties under src/properties directory.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533432

You don't compile a .properties file, you use it as is.

If you use a FileInputStream it will use the working directory which is set in your Run configuration (most likely the top directory)

But you are loading it as a resource which means it must be in your class path. The simplest thing to do is to create a sub-directory for your configuration and add this to your programs class path.

Upvotes: 0

Related Questions