Android reads a small example of the Properties configuration file

  • 2020-05-26 10:04:47
  • OfStack

Development and application of time there will be more likely to become 1 values, such as 1 some ID webservice address applications, etc., before 1 straight are directly change the code in the application, not forget the forgotten points that, so think of can use Properties configuration files, I put the url variable configuration such as the configuration file, so then you have to do is to change the configuration file directly, need not change the code
Here's how to use Properties

 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;
 }

I've put the configuration file in assets and you can put it in raw and you can put it in the same level as our Java file so that we can read the Properties value
The configuration file is easy to write:
For example, url= www.ofstack.com

Related articles: