Read data from properties file in java

Read data from properties file in java

In this tutorial i am going to cover the topic how to read data from properties file in java.

properties file contains data in key and value formate


suppose i have a file inside my /src/main/resources folder name and contains data like

name = javaDream

age = 24

job_profile = software Developer

So if you want to read the data from then add the following code inside your main method


InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(“”);
Properties properties = new Properties();

//For display name

System.out.println(properties.getProperty(“name “));

//For display Age

System.out.println(properties.getProperty(“age “));

//For display Job Profile

System.out.println(properties.getProperty(“job_profile “));

Help Others, Please Share

Leave a Reply

Your email address will not be published. Required fields are marked *