get Properties By Class Loader - Java java.util

Java examples for java.util:Properties File

Description

get Properties By Class Loader

Demo Code


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

public class Main{
    /*from  w  w  w .ja v  a2  s .  c  om*/
    public static Properties getPropertiesByClassLoader(String propFileName) {
        Properties prop = new Properties();
        InputStream input = PropertiesUtil.class.getClassLoader()
                .getResourceAsStream(propFileName);
        try {
            prop.load(input);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return prop;
    }
}

Related Tutorials