JavaWeb---读取 .properties 配置文件

需要将一些 易变 的 配置参数
放置再 XML 配置文件 或者 properties 配置文件中。

基于ClassLoder读取配置文件:【该方式只能读 类路径下 的配置文件】

	Properties properties = new Properties();
	
    // 使用ClassLoader加载properties配置文件生成对应的输入流
    InputStream in = PropertiesMain.class.getClassLoader().getResourceAsStream("config/config.properties");
  
    // 使用properties对象加载输入流
    properties.load(in);
    
    //获取key对应的value值
    properties.getProperty(String key);
发布了16 篇原创文章 · 获赞 12 · 访问量 4833

猜你喜欢

转载自blog.csdn.net/weixin_45881192/article/details/104089175