文章詳情頁
Properties 持久的屬性集的實例詳解
瀏覽:433日期:2022-06-07 09:22:30
Properties 持久的屬性集的實例詳解
特點:
1、Hashtable的子類,map集合中的方法都可以用。
2、該集合沒有泛型。鍵值都是字符串。
3、它是一個可以持久化的屬性集。鍵值可以存儲到集合中,也可以存儲到持久化的設(shè)備(硬盤、U盤、光盤)上。鍵值的來源也可以是持久化的設(shè)備。
// 根據(jù)key讀取value
public void readValue(String filePath, String key) {
Properties props = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
//Thread.currentThread().getContextClassLoader().getResourceAsStream("eop.properties");
props.load(in); // 從輸入流中讀取屬性列表(鍵和元素對)
String value = props.getProperty(key);
}
// 讀取properties的全部信息
public static void readProperties(String filePath) {
Properties props = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String value = props.getProperty(key);
}
}
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
標(biāo)簽:
JSP
相關(guān)文章:
1. Spring中@Value讀取properties作為map或list的操作2. Java加載properties文件實現(xiàn)方式詳解3. IDEA中application.properties的圖標(biāo)顯示不正常的問題及解決方法4. java 如何讀取properties文件5. Java中使用Properties配置文件的簡單方法6. 解決springboot利用ConfigurationProperties注解配置數(shù)據(jù)源無法讀取配置信息問題7. Java中Properties 類的詳細(xì)使用8. Java 獲取properties的幾種方式9. springboot 如何修改默認(rèn)端口及application.properties常用配置10. 在python中修改.properties文件的操作
排行榜

網(wǎng)公網(wǎng)安備