Java Properties Load from File loadPropertiesFromFile(Class clazz, String filePath)

Here you can find the source of loadPropertiesFromFile(Class clazz, String filePath)

Description

load by clazz

License

Open Source License

Declaration

public static Properties loadPropertiesFromFile(Class<?> clazz, String filePath) throws IOException 

Method Source Code


//package com.java2s;
/*/* w w w  .  j av  a  2 s. c  om*/
* Copyright 2016 Yonyou Corporation Ltd. All Rights Reserved.
*
* This software is published under the terms of the Yonyou Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : cmol.common.function
*
* @File name : PropertiesUtils.java
*
* @Author : zhangxianchao
*
* @Date : 2016?4?15?
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016?4?15?    zhangxianchao    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/

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

public class Main {
    /**
     * load by clazz
     */
    public static Properties loadPropertiesFromFile(Class<?> clazz, String filePath) throws IOException {
        InputStream inputStream = clazz.getClassLoader().getResourceAsStream(filePath);
        return loadPropertiesFromInputStream(inputStream);
    }

    /**
     * load from stream
     */
    public static Properties loadPropertiesFromInputStream(InputStream inputStream) throws IOException {
        Properties pros = new Properties();
        try {
            pros.load(inputStream);
        } catch (IOException ex) {
            throw ex;
        }
        return pros;
    }
}

Related

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