Java读取配置文件的PropertiesUtil工具类

Java 中读取配置文件的工具类封装:


public class PropertiesUtil {



    public static Properties prop = null;

    static {
        prop = new Properties();
        try {
            File file = ResourceUtils.getFile("classpath:config.properties");
            prop = PropertiesLoaderUtils.loadProperties(new FileSystemResource(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static String getValue(String key) {
        return prop.getProperty(key);
    }

}
发布了102 篇原创文章 · 获赞 49 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/SoWhatWorld/article/details/104807659