I am using maven web application.
The following is my project structure where I have placed my properties file.
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