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);

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

 

相关文章:

  • 2022-12-23
  • 2021-11-02
  • 2021-12-17
  • 2022-12-23
  • 2021-08-11
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-06-24
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案