Java – Loading Property File

The properties object contains key and value pair both as a string. The java.util.Properties class is the subclass of
Hashtable.
It can be used to get property value based on the property key. The Properties class provides methods to get data
from properties file and store data into properties file.

Use following sample applicaiton to load a properties file bundled :

 
package com.pwn.property;

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

public class LoadingProperty {
	
	/*user.properties
	name=Naveen
	country=US*/

	public static void main(String[] args) {
		try (InputStream bundledResource = LoadingProperty.class
				.getResourceAsStream("user.properties")) {
			Properties userProperties = new Properties();
			userProperties.load(bundledResource);
			System.out.println("username from property file "
					+ userProperties.get("name"));

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
username from property file Naveen