您的位置:首页 > 运维架构

加载属性文件Properties

2019-03-17 14:24 267 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_44428051/article/details/88618898

package com.sico;

import java.io.*;
import java.util.Properties;

/**

  • ClassLoader用于读取配置文件的信息,配置文件放在classes下
    */
    @SuppressWarnings(“unused”)
    public class ConfigUtils {

    private static Properties prop = null;

    static {

    try {
    InputStream ins = ConfigUtils.class.getClassLoader().getResourceAsStream("nettyConfig.properties");
    BufferedReader br = new BufferedReader(new InputStreamReader(ins));
    prop = new Properties();
    prop.load(br);
    } catch (IOException e) {
    e.printStackTrace();
    }

    }

    public static Integer getClientPort() {
    Integer clientPort = Integer.valueOf((String) prop.get(“client.port”));
    return clientPort;
    }

    public static Integer getServerPort() {
    Integer serverPort = Integer.valueOf((String) prop.get(“server.port”));
    return serverPort;
    }

    public static String getClientUrl() {
    String clientUrl = (String) prop.get(“client.url”);
    return clientUrl;
    }

    public static void main(String[] args) {
    String clientUrl = getClientUrl();
    System.out.println(“clientUrl:”+clientUrl);
    }
    }

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: