myProps.jy
#Script to load properties file. from java.io import File from java.io import FileInputStream from java.util import Properties #Load properties file in java.util.Properties def loadPropsFil(propsFil): inStream = FileInputStream(propsFil) propFil = Properties() propFil.load(inStream) return propFil #Displays all keys and values of properties file. def dispayProps(): myPorpFil = loadPropsFil('D:/myProps.properties') keys = myPorpFil.keySet() for key in keys: print key+': '+myPorpFil.getProperty(key) return if(1): dispayProps()
The properties file to be read.
myProps.properties
dataSourceName=myds host=localhost port=1234 userName=usr password=psswrd
Output after running script.
>>> execfile('D:\myProps.jy') port: 1234 password: psswrd host: localhost userName: usr dataSourceName: myds