日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Jython訪問Java屬性文件的方法一覽

為何需要Jython訪問Java屬性文件

英山網(wǎng)站建設公司創(chuàng)新互聯(lián),英山網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為英山上千余家提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務好的英山做網(wǎng)站的公司定做!

使用Jython的過程中經(jīng)常需要訪問Java屬性文件以得到配置信息。Jython 可以用loadProperties 和getProperty 函數(shù)做到這一點,如下所示:

 
 
 
  1. def loadProperties (source):  
  2.     """ 將Java屬性文件加載入詞典 """ 
  3.     result = {}  
  4.     if type(source) == type(''):    # name provided, use file  
  5.         source = io.FileInputStream(source)  
  6.     bis = io.BufferedInputStream(source)  
  7.     props = util.Properties()  
  8.     props.load(bis)   
  9.     bis.close()  
  10.     for key in props.keySet().iterator():  
  11.         result[key] = props.get(key)  
  12.     return result  
  13.  
  14. def getProperty (properties, name, default=None):  
  15.     """ 取得一個屬性 """ 
  16.     return properties.get(name, default)  

Jython訪問Java屬性文件示例

所以,假如使用的是訪問Java屬性文件 中的函數(shù),如下所示:

 
 
 
  1. import sys     
  2. file = sys.argv[1]     
  3. props = loadProperties(file)     
  4. print "Properties file: %s, contents:" % file      
  5. print props     
  6. print "Property %s = %i" % ('debug', int(getProperty(props, 'debug', '0')))    
  7.  
  8. import sys  
  9. file = sys.argv[1]  
  10. props = loadProperties(file)  
  11. print "Properties file: %s, contents:" % file   
  12. print props  
  13. print "Property %s = %i" % ('debug', int(getProperty(props, 'debug', '0')))  

并且這些函數(shù)具有如下屬性文件內(nèi)容:

 
 
 
  1. # 一個示例用屬性文件     
  2. debug = 1    
  3. error.level = ERROR     
  4. now.is.the.time = false    
  5.  
  6. # 一個示例用屬性文件  
  7. debug = 1 
  8. error.level = ERROR  
  9. now.is.the.time = false  

那么,得到的輸出就會是:

 
 
 
  1. Properties file: test.properties, contents:     
  2. {'error.level': 'ERROR', 'debug': '1', 'now.is.the.time': 'false'}     
  3. Property debug = 1 

以上就是Jython訪問Java屬性文件的實現(xiàn)方法。


分享文章:Jython訪問Java屬性文件的方法一覽
當前地址:http://www.dlmjj.cn/article/dhipjsj.html