首页 > 编程语言 > 详细

使用Java读取配置文件

时间:2016-06-05 17:00:41      阅读:116      评论:0      收藏:0      [点我收藏+]

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

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);
    }
}

  

使用Java读取配置文件

原文:http://www.cnblogs.com/xiohao/p/5560974.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!