Java解析properties文件配置

    /***
     * 解析properties文件配置
     * @param pathName 解析文件名称
     * @param elementName 解析字段
     * @return 返回解析字段的值
     */
    public static Object initProperties(String pathName, String elementName) {
        Properties properties = new Properties();
        String path = Common.class.getClassLoader().getResource(pathName).getPath();
        File file = new File(path);
        try {
            FileInputStream inputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");

            properties.load(inputStreamReader);
            return properties.getProperty(elementName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
原文地址:https://www.cnblogs.com/hanmian4511/p/10875325.html