0

I would like to read a property file, like this:

Properties props = new Properties();
props.load(MajorBot.class.getResourceAsStream("application.properties"));

But when I am trying to do this I get an error:

Exception in thread "main" java.lang.NullPointerException: inStream parameter is null at java.base/java.util.Objects.requireNonNull(Objects.java:246) at java.base/java.util.Properties.load(Properties.java:406) at majorbot.MajorBot.main(MajorBot.java:13)

My app was created using IntelliJ, new Gradle/Java project. After creation, there was a resources directory allready there. I have created application.properties there, but I cannod read this file.

Is there a way to fix this?

1
  • You can try this solution this should work but I didn't tested Commented May 12, 2021 at 21:29

1 Answer 1

0

getResourceAsStream will try to find your file in a subfolder of resources that matches your current class’s package. If you want to access a file that is not in a subfolder, specify it as e.g. “/application.properties”.

Sign up to request clarification or add additional context in comments.

1 Comment

Your suggestion is correct, but it doesn’t use the “current class”—it uses the package of the class whose getResource method is being called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.