Usage and usage of the configuration file property in Android

Source: Internet
Author: User

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");  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.