java讀取resource目錄下的配置文件
阿新 • • 發佈:2018-03-10
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目錄下的配置文件