One, the configuration file config.properties is placed in the SRC root directory: For example, mine is
/propertiestest/src/com/xuliugen/project/type.properties
The contents of the configuration file are as follows:
left=com.sunny.project.LeftHairright=com.sunny.project.RightHairin=com.sunny.project.InHair
Read the code in the configuration file as follows:
Public classPropertiesreader { Public Static void Main(string[] args) {NewPropertiesreader (). GetProperties (); } PublicMap<string, string>getProperties() {Properties props =NewProperties (); map<string, string> map =NewHashmap<string, string> ();Try{InputStreaminch= GetClass (). getResourceAsStream ("Type.properties"); Props.load (inch); Enumeration en = Props.propertynames (); while(En.hasmoreelements ()) {String key = (string) en.nextelement (); String property = Props.getproperty (key); Map.put (key, property); System. out. println (Key +" "+ property); } }Catch(Exception e) {E.printstacktrace (); }returnMap }}
The results of the operation are as follows:
Java language read configuration file config.properties