日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

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

英山網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),英山網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為英山上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的英山做網(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屬性文件的方法一覽
網(wǎng)頁路徑:http://www.5511xx.com/article/dhipjsj.html