1. Create a file named netconfig. properties under the source code root directory (SRC) (or in other directories ).
2. Open the netconfig. properties file and add the following code to the file.
Java code:
# The comment IP address = 192.168.1.111 Port = 3535 MSG = is a long string. <br> we can keep the line breaks and lines unchanged. <br> the comment can be displayed by branch. # The comment IP address = 192.168.1.111port = 3535msg = is a long string. <br> we can keep the line breaks and lines unchanged. <br> the comment can be displayed by branch.
Note: In the code above, # is the comment in the configuration file. In the configuration file, you can use <br> to process the format. In the configuration file, if an attribute is too long, A row cannot be completely entered. You can use the \ Notification System. The next row is also the value of this attribute.
3. Create a tool class utils class. The code is listed below.
* ** @ Description: tool class * @ version 1.0 * @ created on 02:39:52 */public class utils {/*** get netconfig. all configuration properties in the properties configuration file ** @ return properties object */public static properties getnetconfigproperties () {properties props = new properties (); inputstream in = utils. class. getresourceasstream ("/netconfig. properties "); try {props. load (in);} catch (ioexception e) {e. printstacktrace ();} return props ;}}
4. When you need to use the property value configured in the configuration file, you can directly call the above method, as shown below.
String IP = Utils.getNetConfigProperties().getProperty("IP");