2

I am using maven web application. The following is my project structure where I have placed my properties file.

enter image description here

The following is my code which I am using to read this file:

public static Properties loadProducerProperty() throws FileException { Properties myProperties = new Properties(); try { String resourceName = "newproperties.properties"; // could also be a constant ClassLoader loader = Thread.currentThread().getContextClassLoader(); try (InputStream resourceStream = loader.getResourceAsStream(resourceName)) { myProperties.load(resourceStream); } } catch (FileNotFoundException e) { throw new FileException(); } catch (IOException e) { throw new FileException(); } return myProperties; } 

But I am getting FileNotFound Exception

I have gone through the following link and tried other things also but I am getting the same error :

Cannot load properties file from resources directory

What I am doing wrong here.

Thank you

0

1 Answer 1

2

Add a slash in front of the filename:

String resourceName = "/newproperties.properties"; // could also be a constant 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.