ITeye博客

android properties

micc010 · 2011-04-07 23:52 · android · 移动开发 · Markdown

使用Properties类来解析

方法一:因为最终是通过流文件来进行properties文件读取的,所以很自然,我们想到要将文件放入到assets文件夹或者raw文件夹中了。

例如,我们这里有一个文件——>test.properties,如果放入了assets文件夹中,可以如下打开

Properties pro = new Properties();

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

pro.load(is);

如果放入到raw文件夹中,可以通过如下方式打开

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

方法二:没有上下文的加载!

android中的资源文件是只能存放在assets或者res的子目录里面的,将.properties文件放入到assets文件夹里,而在传入路径里面填入文件绝对路径,还是可以引用该文件的。

pro.load(Any.class.getResourceAsStream("/assets/test.properties")); 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。