java讀取配置檔案property

2021-05-25 21:27:10 字數 826 閱讀 3109

properties pro = new properties();

try  catch (filenotfoundexception e)  catch (ioexception e) 

//propertynames(),返回屬性列表中所有鍵的列舉

enumeration enu2=pro.propertynames();

while(enu2.hasmoreelements()) 

//properties 繼承於 hashtable,elements()是hashtable的方法,返回雜湊表中的值的列舉。

enumeration enu=pro.elements();

while(enu.hasmoreelements()) 

//properties 繼承於 hashtable,entryset()是hashtable的方法,

//返回此 hashtable 中所包含的鍵的 set 檢視。此 collection 中每個元素都是乙個 map.entry

iterator it=pro.entryset().iterator();

while(it.hasnext())

假設wahaha.properties中內容為:

name1=***x

name2=yyyyy

name3=zzzzzzz

上面的**將會輸出:

name1

name2

name3

***x

yyyyy

zzzzzzz

name1:***x

name2:yyyyy

name3:zzzzzzz

java 讀取配置檔案

前幾天因為配置檔案的事,線上的job掛掉了,使用的是spring載入配置檔案方式。spring配置如下 test.properties api test.properties decryptpropertyplaceholderconfigurer類如下所示。public class decrypt...

java讀取配置檔案

現今的程式都要求能夠讀寫配置檔案,使得程式的配置資訊能夠很方便地修改。讀取配置檔案通常使用property檔案,下面列舉了從hadoop的hdfs和本地的檔案系統讀取配置的例子。話不多說,上 讀取hdfs配置檔案 public static properties getpropertiesfromh...

Java讀取Properties配置檔案

properties類繼承自hashtable類並且實現了map介面,使用鍵值對的形式來儲存屬性集。不過properties的鍵和值都是字串型別。1 load inputstream instream 此方法可以從.properties屬性檔案對應的檔案輸入流中,載入屬性列表到properties類...