Java Utililty Methods Properties Load from File

List of utility methods to do Properties Load from File

Description

The list of methods to do Properties Load from File are organized into topic(s).

Method

MaploadPropertiesFile(String propertiesFileName)
load Properties File
Properties properties = new Properties();
properties.load(new FileInputStream(propertiesFileName));
return (Map) properties;
PropertiesloadPropertiesFile(String propFile)
Loads properties from file.
Properties fProps = new Properties();
try (InputStream is = new FileInputStream(new File(propFile))) {
    fProps.load(is);
return fProps;
PropertiesloadPropertiesFile(String propFilePath)
load Properties File
try (InputStream input = new FileInputStream(propFilePath)) {
    return loadPropertiesStream(input);
PropertiesloadPropertiesFromClasspath(final String filename)
Loads Properties using current thread's classloader.
Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename));
return properties;
PropertiesloadPropertiesFromClasspath(Class loadResourceClass, String classpath)
load Properties From Classpath
Properties aprops = new Properties();
InputStream ios = loadResourceClass.getResource(classpath).openStream();
aprops.load(ios);
return aprops;
PropertiesloadPropertiesFromClasspath(String pfname)
load Properties From Classpath
Properties p = new Properties();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream(pfname);
if (is == null)
    throw new RuntimeException("Could not find " + pfname + " in CLASSPATH");
try {
    p.load(is);
} catch (Exception e) {
...
PropertiesloadPropertiesFromFile(Class clazz, String filePath)
load by clazz
InputStream inputStream = clazz.getClassLoader().getResourceAsStream(filePath);
return loadPropertiesFromInputStream(inputStream);
MaploadPropertiesFromFile(JarFile jar)
load Properties From File
Map<String, String> result = new HashMap<String, String>();
Properties props = new Properties();
JarEntry entry = jar.getJarEntry("conf/plugin.properties");
if (entry != null) {
    InputStream in = jar.getInputStream(entry);
    props.load(in);
    Enumeration<?> en = props.propertyNames();
    while (en.hasMoreElements()) {
...
InputStreamloadPropertiesFromFile(String configFile)
load Properties From File
final InputStream input = new FileInputStream(configFile);
final Properties prop = new Properties();
prop.load(input);
server = prop.getProperty("ras.server", DEFAULT_SERVER);
database = prop.getProperty("ras.database", DEFAULT_BASE);
port = prop.getProperty("ras.port", DEFAULT_PORT);
username = prop.getProperty("ras.username", DEFAULT_USER);
password = prop.getProperty("ras.password", DEFAULT_PASSWD);
...
PropertiesloadPropertiesFromFile(String filePath)
load Properties From File
File configFile = new File(filePath);
if (!configFile.exists()) {
    throw new FileNotFoundException("Configuration file \"" + filePath + "\" could not be found");
System.out.println("Configuration file located in " + filePath);
InputStream inputStream = new FileInputStream(filePath);
return loadProperties(inputStream);