1. 程式人生 > >java讀取resource目錄下的配置文件

java讀取resource目錄下的配置文件

inf 技術 AR except etc pan rop parse 分享圖片

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目錄下的配置文件