I have never noticed that the configuration file can be well written.
From: http://hi.baidu.com/ai5173609/blog/item/30e1a28fb6de21fe503d927d.html
All languages have their own Supported configuration file types. For example, Python supports. ini files. Because it has a configparser class to support reading and writing. ini files, according to the method provided by this classProgramYou can operate the. ini file as needed. In Java, JAVA supports reading and writing the. properties file. The built-in JAVA. util. properties class of JDK provides convenience for us to operate on the. properties file.
1. properties File Format
# Server and database information
Dbport = localhost
Databasename = mydb
Dbusername = root
Dbpassword = root
# The following table information
Dbtable = mytable
# Server Information
IP = 192.168.0.9
In the preceding file, assume that the file name is test. properties. Where # the start line is the comment information. The key on the left side of the equal sign "=" is called the key, and the value on the right side of the equal sign "=" is called the value. (In fact, we often say that the key-Value Pair) key should be a variable in our program. Value is configured according to the actual situation.
2. The properties class of JDK exists in the cell java. util, which inherits from hashtable and provides several main methods:
1. getproperty (string key). Use the specified key to search for properties in this attribute list. That is, the value corresponding to the key is obtained through the key parameter.
2. Load (inputstream instream), read the attribute list (key and element pair) from the input stream ). You can load the specified file (such as the test. properties File above) to obtain all key-value pairs in the file. For getproperty (string key) search.
3. setproperty (string key, string value): Call the hashtable method put. He sets key-value pairs by calling the PUT Method of the base class.
4. Store (outputstream out, string comments) writes the attribute list (key and element pair) in the properties table to the output stream in a format suitable for loading to the properties table using the load method. In contrast to the load method, this method writes a key-value pair to a specified file.
5. Clear () to clear all loaded key-value pairs. This method is provided in the base class.