首页 > 代码库 > java读取properties文件工具

java读取properties文件工具

public class PropertiesUtil {

    public static String get(String filePath, String key) {
        String val = null;
        Properties prop = new Properties();
        InputStream in = null;
        in = PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath);
        try {
            prop.load(in);
            val = (String) prop.get(key);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return val;
    }
}

 

java读取properties文件工具