美文网首页
java读取配置文件

java读取配置文件

作者: 夜空最亮的9星 | 来源:发表于2018-08-06 14:35 被阅读75次

方法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

相关文章

网友评论

      本文标题:java读取配置文件

      本文链接:https://www.haomeiwen.com/subject/evxgvftx.html