Android read a small example of a properties configuration file _android

Source: Internet
Author: User
Development of the application will have some may become a value, such as WebService address application of some IDs, etc., has been directly in the application of the code, not forget the point that, then think of the properties can be used configuration file, I put the URL and other variables configured in the configuration file, After that, you can change the configuration file directly, you do not need to change the code
Let's talk about the use of properties
Copy Code code as follows:

public static string Getpropertiesurl (context C, String s) {
String URL = null;
Properties Properties = new properties ();
try {
Properties.load (C.getassets (). Open ("property.properties"));
url = properties.getproperty (s);
catch (Exception e) {
E.printstacktrace ();
}
return URL;
}

Here I put the configuration file in the Assets folder, you can also be placed under raw or with our Java file siblings so we can read the properties of the value of the
The configuration file is written very simply:
For example Url=www.jb51.net on line comment with # #
Related Article

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.