Code Robo
Formatter
Comparator
Tester
Merger
Converter
Utility
Java Code Complience
Validator
EncoderDecoder
Virtual Service
Java Code To Load Properties And Cache Them
       Talk to EasyAssistant

Property Manger java code provides sample java method to load the properties from a propertyfile and cache it in a singletone object. Code shown here can be copied from here and used in any java project. It uses java.util.Properties class e.


Java Property Manager File Content:
 package test.easycodeforall.singletone;

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

public final class PropManager {

	private static PropManager obj = new PropManager();
	private Properties prop = null;
	private String propFileName = "easycodeforall.properties";

	private PropManager() {
		loadProperties();
	}

	public void refreshCache() {
		loadProperties();
	}

	private void loadProperties() {
		try {
			prop = new Properties();
			InputStream propAsStream = this.getClass().getResourceAsStream(propFileName);
			prop.load(propAsStream);
		} catch (Exception ex) {
			System.out.println("Unable to load properties from " + propFileName + ". Exception=" + ex);
		}
	}

	public static PropManager getInstance() {
		return obj;
	}

	public String getProperty(String propertyName) {
		return prop.getProperty(propertyName);
	}
}
 




Please provide your feedback here
It has been explained in this video (https://youtu.be/bxkNb0GuELY). Please watch it.
 



Post Your Comment:
Name :
Email ( Optional) :
Comments / Suggestion (* Required) It is required: :
: