to read properties file android

sponsored links
java properties frequently used files, and then by using the Properties class to parse, and is not state the benefits of using the properties file, mainly on how to use properties file in the android!

Method One: because in the end flow of documents through the properties file to be read, so naturally, we think of assets to file into the folder or folder in the raw.

For example, here we have a file -> test.properties, if put into the assets folder, you can open the following

Properties pro = new Properties ();

InputStream is = context.getAssets (). Open ("test.properties");

pro.load (is);

If put to the raw folder, you can open the following

InputStream is = context.getResources (). OpenRawResource (R.raw.test);

However, sometimes we do not want to get android context (context), but as the standard method of loading java properties file, then how do we use it? See Method Two:

Method Two: There is no context to load! [Recommend Us]

Properties pro = new Properties ();

pro.load (FileLoad.class.getResourceAsStream ("test.properties"));

Which, FileLoad loading method is the class where the class name. test.properties the path stored in the same package with FileLoad.java.

However, in android, when we generate apk package, it will put apk to a real phone, you will not find test.properties file, do not be surprised, android in the resource file is only stored in the assets or res subdirectories inside the package in the resource file is compiled, will be lost! It is not our second method would not be able to use it? Of course not, after the experiments showed that the file into the assets folder, fill in the incoming path of the file inside the absolute path, or can refer to the file.

Code: pro.load (FileLoad.class.getResourceAsStream ("/ assets / test.properties"));

Note: The path to the root of the project which is "/"

This way, you can successfully use your Properties files! o (∩ ∩) o. .. haha
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of to read properties file android

  • Org.directwebremoting package of DWR

    Org.directwebremoting package structure AjaxFilter.java Two types of interface 1, certification, log, security 2, the delay AjaxFilterChain cooperation in general and org.directwebremoting.filter.ExtraLatencyAjaxFilter Container Vessels Hub Hub, prov ...

  • Spring package structure, and cited relations between the various packages that

    Keyword: Spring Spring package structure Description:   spring.jar Includes a complete release of a single jar package. In addition to have him included in spring-mock.jar all but jar. The reason is that, spring-mock.jar only in the development environmen

  • Rails 2.2 new features

    October 24, Rails has released a preview of 2.2 version of history on Rails This is a major version upgrade! Mainly includes the following major changes: 1, support internationalized! Rails2.2 integrates a i18n framework, and put all the tips Rails i ...

  • XForms combines rails and (2) (see IBM out-patient)

    (2) modify user . / script / generate controller load loading load_all Generate a controller and a load and load_all two action Add Page edit_user.xhtml Look at the load / loading of the action Modify template index.erb Modify users / update Click Ed ...

  • Basic Auth HTTP Request in Ruby

    At present the majority of domestic micro-Bo (mini blog) are open api HTTP Basic Access Authentication For authentication. Including rice not, sharawadgi askew, and even chat JavaEye. Twitter is now certified to use OAuth way. Is to sum up with ruby ...

  • fastcgi init script on centos enhanced version

    On the / etc / init.d / below to facilitate

  • rails version of the change (b) - rails of the introduction

    Prompted the new Rails 2.2 features October 24, Rails has released a preview version 2.2, Rails This is the history of a major version upgrade! Mainly includes the following major changes: 1, support internationalized! Rails2.2 integrates a i18n framework

  • Struts + Spring + Hibernate practice

    Tools: Eclipse3.1, MyEclipse4.03, Tomcat5.5.9, Properties Editor plug-ins, MySql4.1.13 New construction: the name for the login Create Struts framework Create index.jsp, add a link to login.jsp Press Ctrl + N, to create login.jsp, LoginAction, the use of

  • Struts2 Spring Hibernate integration of easy

    1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

  • Struts2 Spring Hibernate's easy to integrate

    1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries