Read properties file in java

To read a properties file in Java, you can use the java.util.Properties class. You can follow these steps in the article below

//: # ()

Here are the steps to read a properties file in Java using bullet points:

Import the java.util.Properties class. Create a new Properties object. Create a new FileInputStream object and pass the path of the properties file as an argument. Load the properties file into the Properties object using the load() method of the Properties class. Access the properties of the file using the getProperty() method of the Properties class.

Here’s an example of how to read a properties file using this class:

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class ReadPropertiesFile {
    public static void main(String[] args) {
        Properties prop = new Properties();
        try {
            FileInputStream fis = new FileInputStream("config.properties");
            prop.load(fis);
            System.out.println(prop.getProperty("database"));
            System.out.println(prop.getProperty("dbuser"));
            System.out.println(prop.getProperty("dbpassword"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}