标签:
实现起来,相对比较简单,留个备案吧,废话也不多说,请看代码:
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);
}
}
标签:
原文地址:http://www.cnblogs.com/xiohao/p/5560974.html