---
title: "android properties"
author: "micc010"
date: "2011-04-07T23:52:11Z"
tags: []
categories: ["移动开发"]
slug: "android-properties"
draft: false
lastmod: "2011-04-07T23:56:38Z"
id: 991344
url: "https://micc010.iteye.com/blog/991344"
---

使用Properties类来解析

  方法一：因为最终是通过流文件来进行properties文件读取的，所以很自然，我们想到要将文件放入到assets文件夹或者raw文件夹中了。 

  例如，我们这里有一个文件——>test.properties，如果放入了assets文件夹中，可以如下打开


```java
Properties pro = new Properties();

  InputStream is = context.getAssets().open("test.properties"); 

pro.load(is);
```


  如果放入到raw文件夹中，可以通过如下方式打开

 
```java
 InputStream is = context.getResources().openRawResource(R.raw.test);
```



方法二：没有上下文的加载！

android中的资源文件是只能存放在assets或者res的子目录里面的，将.properties文件放入到assets文件夹里，而在传入路径里面填入文件绝对路径，还是可以引用该文件的。


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