Java Properties Load from File loadPropertiesFromClasspath( final String filename)

Here you can find the source of loadPropertiesFromClasspath( final String filename)

Description

Loads Properties using current thread's classloader.

License

Open Source License

Parameter

Parameter Description
filename - properties filename

Exception

Parameter Description
IOException an exception

Return

object, never null

Declaration

static final Properties loadPropertiesFromClasspath(
        final String filename) throws IOException 

Method Source Code

//package com.java2s;

import java.io.IOException;

import java.util.Properties;

public class Main {
    /**/*from  ww w.  j a va 2s  . c o  m*/
     * Loads {@link Properties} using current thread's classloader. Here <i>filename</i> is supposed to be placed in
     * one of the roots which are covered by the default classpath of a webapp, e.g. <code>Webapp/WEB-INF/lib</code>,
     * <code>Webapp/WEB-INF/classes</code>, <code>Appserver/lib</code> or <code>JRE/lib</code>. If the properties file
     * is webapp-specific, best is to place it in <code>WEB-INF/classes</code>. If you're developing a project in an
     * IDE, you can also drop it in <code>src</code> folder (the project's source folder).
     * <p>
     * You can alternatively also put it somewhere outside the default classpath and add its path to the classpath of
     * the appserver. In for example Tomcat you can configure it as <code>shared.loader</code> property of
     * <code>Tomcat/conf/catalina.properties</code>.
     *
     * @param filename - properties filename
     * @return {@link Properties} object, never <code>null</code>
     * @throws IOException
     */
    static final Properties loadPropertiesFromClasspath(
            final String filename) throws IOException {
        Properties properties = new Properties();
        properties.load(Thread.currentThread().getContextClassLoader()
                .getResourceAsStream(filename));
        return properties;
    }
}

Related

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