Java reading properties files




















Skip to content. Change Language. Related Articles. Table of Contents. Improve Article. Save Article. Like Article. Last Updated : 29 Nov, Driver" ;. ResultSet rs. ResourceBundle rd. Attention reader! Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. NullPointerException at java. Jesper k 44 44 gold badges silver badges bronze badges.

Add a comment. Active Oldest Votes. Mark Elliot Mark Elliot 71k 19 19 gold badges silver badges bronze badges. I did what you advised me but it still throws the same exception — nikos. Steven Gomez Steven Gomez 5 5 silver badges 2 2 bronze badges. Don't forget to close the Reader in prop. There are many methods in that link.

Why did you choose the one with class loader? Are there any advantages or disadvantages of that method? You can use ResourceBundle class to read the properties file. Paul Vargas This approach is recommended for i18n. My use case is for Jenkins so it's nice to have a solution that doesn't rely upon a bunch of ClassPathLoader shenanigans.

You can't use this keyword like - props. Mukus Mukus 4, 2 2 gold badges 37 37 silver badges 54 54 bronze badges. ApplicationContext is available only in case of Spring application — joro.

Then load it as: props. Since your properties file is not at the root of your project, you don't need the leading slash. I was getting the exception thrown in the first place without the leading slash. It's still not working. You can use java. Tarun Jain Tarun Jain 1 1 silver badge 7 7 bronze badges. How to convert InputStream to File in java?

I wanted to read. Top 3 video Explaining java - How to read an external properties file in Maven. Avoiding NullPointerException in Java. How do I generate random integers within a specific range in Java? How can I create a memory leak in Java? What is the difference between public, protected, package-private and private in Java?



0コメント

  • 1000 / 1000