java读取resource目录下的配置文件

java读取resource目录下的配置文件

    1:配置resource目录 下的文件 

       

host: 127.0.0.1
port: 9300

2:读取    / 代表resource目录

        InputStream in = this.getClass().getResourceAsStream("/config.properties");
        Properties properties = new Properties();
        try {
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String host = properties.getProperty("host");
        String port = properties.getProperty("port");
        int intport = Integer.parseInt(port);

原文地址:https://www.cnblogs.com/liyafei/p/8538284.html