实现起来,相对比较简单,留个备案吧,废话也不多说,请看代码:

package com.jd.***.config;

import org.junit.*;

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

/**
 * 用Java读取一个配置文件
 *
 * Created by zhanghao10 on 2016/6/5.
 */
public class TestProperties {

    @org.junit.Test
    public void test() throws IOException {
        Properties properties=new Properties();
        InputStream inputStream=this.getClass().getClassLoader().getResourceAsStream("config.properties");
        properties.load(inputStream);
        String value= (String) properties.get("clientPort");
        System.out.println("对应的值为clientPort:"+value);
    }
}

  

相关文章:

  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-08-20
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-03-06
  • 2022-02-13
相关资源
相似解决方案