android 获取Asset中Properties文件配置的键值对
/**
* android 获取Asset中Properties文件配置的键值对
* @param context
* @param key
* @return
*/
public static String getProperties(Context context,String key){
String defaultValues = "";
InputStream inputStream = null;
try {
AssetManager assetManager = context.getApplicationContext().getAssets();
String confFile = "kuda.properties";
inputStream = assetManager.open(confFile);
Properties properties = new Properties();
properties.load(new InputStreamReader(inputStream, "utf-8"));
String value = properties.getProperty(key,defaultValues);
return value;
} catch (IOException e) {
e.printStackTrace();
}
return defaultValues;
}
该代码段展示了一个在Android中从Asset目录下的Properties文件读取配置键值对的方法。它通过AssetManager打开文件,加载到Properties对象中,然后使用getProperty方法获取指定键的值。
3074

被折叠的 条评论
为什么被折叠?



