Java Properties Load from File loadPropertiesFromClasspath(String pfname)

Here you can find the source of loadPropertiesFromClasspath(String pfname)

Description

load Properties From Classpath

License

Open Source License

Declaration

public static Properties loadPropertiesFromClasspath(String pfname) 

Method Source Code

//package com.java2s;
/*// w  w w.j a  va2  s. co  m
 * Copyright (c) 2010, Joshua M. Clulow. All rights reserved.
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 */

import java.io.InputStream;

import java.util.Properties;

public class Main {
    public static Properties loadPropertiesFromClasspath(String pfname) {
        Properties p = new Properties();
        // ClassLoader cl = ClassLoader.getSystemClassLoader();
        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) {
            throw new RuntimeException("Could not load " + pfname + ": " + e.getMessage());
        }
        return p;
    }
}

Related

  1. loadPropertiesFile(String propertiesFileName)
  2. loadPropertiesFile(String propFile)
  3. loadPropertiesFile(String propFilePath)
  4. loadPropertiesFromClasspath( final String filename)
  5. loadPropertiesFromClasspath(Class loadResourceClass, String classpath)
  6. loadPropertiesFromFile(Class clazz, String filePath)
  7. loadPropertiesFromFile(JarFile jar)
  8. loadPropertiesFromFile(String configFile)
  9. loadPropertiesFromFile(String filePath)