Java Properties File: How to Read config.properties Values in Java?

05:48:00 , 0 Comments

Crunchify Get Properties Value in Java
.properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
Each parameter is stored as a pair of strings, one storing the name of the parameter (called the key/map), and the other storing the value.
Below is a sample Java program which demonstrate you how to retrieve/read config.properties values in Java. For update follow this tutorial.
Another must read:  Read config.properties value using Spring “singleton” Scope in your Java Enterprise Application

We will create 3 files:

  1. CrunchifyReadConfigMain.java
  2. CrunchifyGetPropertyValues.java
  3. config.properties file
Main Class (CrunchifyReadConfigMain.java) which will call getPropValues() method from class CrunchifyGetPropertyValues.java.
Lets 1st create config.properties file.
  1. Create Folder “resources” if your project doesn’t have it.
  2. create config.properties file with below value.
Config.properties under resource folder
Output:
As usually happy coding and enjoy..!! Do let me know if you see any exception

0 comments :