Java 讀取 properties 文件

加載當前類路徑下的 properties 文件

 

Properties properties = new Properties();
// 使用ClassLoader加載properties配置文件生成對應的輸入流
InputStream in = 當前類名.class.getClassLoader().getResourceAsStream("emailConfig.properties");
// 使用properties對象加載輸入流
properties.load(in);
//獲取key對應的value值
account=properties.getProperty("account");
password=properties.getProperty("password");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章