您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页java读取配置文件

java读取配置文件

来源:二三娱乐

方法1


public class Hello {

    //读取配置文件信息
    private static InputStream inputStream = null;
    private static Properties properties = null;
    private static String server;
    private static String code;
    private static String address;
    private static String protocol;
    static {
        try{
            properties = new Properties();
            inputStream = Thread.class.getResourceAsStream("/user.properties");
            properties.load(inputStream);
            server = properties.getProperty("server");
            code = properties.getProperty("code");
            protocol = properties.getProperty("protocol");
            address = properties.getProperty("address");
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(inputStream != null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

方法2

image

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务