Reading the External properties file using java

This example shows how to load the external properties file and get the data of properties.

Reading Properties

Here is my propeties file JavaSnippets.properties file.
Name = javasnippets
Admin = janardhan randhi
Address= vizianagaram 
Here is my java class
package com.externalProperties;

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

/**
 *
 * @author Janardhan Randhi
 */
public class ReadingExternalPropertiesFile {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        Properties p = new Properties();
        InputStream i = new FileInputStream("JavaSnippets.properties");
        p.load(i);
        System.out.println("Blog name is :::::::" + p.getProperty("Name"));
        System.out.println("Admin name is :::::::" + p.getProperty("Admin"));
        System.out.println("Address  is :::::::" + p.getProperty("Address"));
    }
}
Explanation:
  • Create the properties class instance to read the properties.
  • Next, create the input stream instance for reading the external properties file physical location.
  • use the predefined method load use to load the properties file.
  • Using the get property method to get the values of given keys.