基于java讀取并引用自定義配置文件
首先在resources目錄創建自定義的配置文件
配置文件的格式:
寫工具類,得到配置參數
import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class MyConfig { public static Properties myProp = new Properties(); public static InputStream myResource = MyConfig.class.getResourceAsStream('/myConfig.properties'); static { try { myProp.load(myResource); } catch (IOException e) { e.printStackTrace(); } } public String getMyConf(String props) { return myProp.getProperty(props); } public static void main(String[] args) { final MyConfig myConfig = new MyConfig(); System.out.println(myConfig.getMyConf('master_ip')); }}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. React+umi+typeScript創建項目的過程2. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析3. SharePoint Server 2019新特性介紹4. ASP中常用的22個FSO文件操作函數整理5. 三個不常見的 HTML5 實用新特性簡介6. ASP調用WebService轉化成JSON數據,附json.min.asp7. .Net core 的熱插拔機制的深入探索及卸載問題求救指南8. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁9. 讀大數據量的XML文件的讀取問題10. 解決ASP中http狀態跳轉返回錯誤頁的問題
