java配置文件读取工具类


#dev.properties如下
# 测试配置
test.url=127.0.0.1/login

 

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

public class ReadConfigUtils {

    private static Properties properties = new Properties();

    public static final String PROP_FILE_NAME = "dev.properties";

    static {
        try {
            properties.load(ReadConfigUtils.class.getClassLoader()
                    .getResourceAsStream(PROP_FILE_NAME));
        } catch (IOException e) {
        }
    }

    public static String getProperties(String key) {
        return properties.getProperty(key);
    }
}

使用方法

private static String url= null;          // url

    static
    {
        url = ReadConfigUtils.getProperties("test.url"); 
}

 

posted @ 2021-04-15 23:51  不该懂的还是懂了  阅读(170)  评论(0)    收藏  举报