Java ClassLoader load(String propertiesName)

Here you can find the source of load(String propertiesName)

Description

Utility to load a properties file from the classpath.

License

Open Source License

Parameter

Parameter Description
propertiesName name of the properties file. The file needs to be on the classpath.

Exception

Parameter Description
IOException IOException

Return

Properties

Declaration

public static Properties load(String propertiesName) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;
import java.net.URL;
import java.util.Properties;

public class Main {
    /**/*w ww.  ja  v  a2 s .c  o m*/
     * Utility to load a properties file from the classpath.
     * @param propertiesName name of the properties file. The file needs to be on the classpath.
     * @return Properties
     * @throws IOException IOException
     */
    public static Properties load(String propertiesName) throws IOException {
        Properties p = new Properties();
        URL url = ClassLoader.getSystemResource(propertiesName);
        if (url == null) {
            throw new FileNotFoundException("Properties file not on classpath: " + propertiesName);
        }

        InputStream is = url.openStream();
        try {
            p.load(is);
        } finally {
            is.close();
        }
        return p;
    }
}

Related

  1. hasLogDatePatternMatcher(final String line)
  2. isExist(String path)
  3. isVMAlive(String procId)
  4. load(File propsFile)
  5. load(final String filename)
  6. load(String propsName)
  7. loadAttachApi()
  8. loadCorrectedConfiguration(String configurationFilename)
  9. loadFile(String file)