Android项目中的配置属性文件 [英] Configuration properties file in Android project

查看:336
本文介绍了Android项目中的配置属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Android项目中的哪里放置配置文件?目前,我在res目录中的目录为: res/config/configuration.properties

Where can I place configuration file in Android project? Currently I am made a directory in res directory as : res/config/configuration.properties

and want to access it as :
properties = new Properties();
properties.load(getClass().getResourceAsStream("config/configuration.properties"));

它不起作用:输入流为空

It is not working : input stream is null

推荐答案

您可以将其作为 assets/configuration.properties

示例代码

try {
    InputStream is = context.getAssets().open("configuration.properties");
    Properties props = new Properties();
    props.load(is);

    String value = props.getProperty("key", "");

    is.close();
} catch (Exception e) {
}

这篇关于Android项目中的配置属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆