To read the configuration file in Android, you can read it using the System.getproperties () method:
1, under the RES resource directory, create a new folder, Raw, and under which a. properties file is created. For example:
Request_char=utf-8url=http://192.168.1.101:8080/serveraqi/jsonactionrange_long=7#daysfrom_date_name=fromdateto _date_name=todate
2, you can define a tool class that accepts parameters of the Android.content.res.Resources type and returns the Properties object, such as:
package Spt.assist;import Java.io.ioexception;import Java.util.properties;import Android.content.res.resources.notfoundexception;import Android.util.Log;import Spt.aqi.activity.r;public class Propertyconfig {/** Gets the specified value in the profile information. * @param resources * @param key * @return */public Stati C String GetProperty (android.content.res.Resources resources,string key) {Properties properties = getProperties ( resources); return Properties.getproperty (key);} /** gets the information in the configuration file. * @param resources * @return */public static Properties getProperties (android.content.res.Resources resources) { Properties Props = new properties (); try {props.load (Resources.openrawresource (r.raw.properties));} catch ( Notfoundexception e) {log.i ("Sysout", "Resourcesearcher:openfilefromutil:" + e.getmessage ()); E.printstacktrace (); return null;} catch (IOException e) {log.i ("Sysout", "Resourcesearcher:openfilefromutil:" + e.getmessage ()); E.printstacktrace (); return null;} return props;}}
3, call the Getresources () method in the subclass of the resource class contextwrapper (such as the activity or service) class in Android, and pass in the method of the tool class above, for example, in the service class,
Final String url = propertyconfig.getproperty (Getresources (), "url");
Android-Read the properties configuration file