Android 项目中的配置属性文件

Configuration properties file in Android project

我可以在 Android 项目的什么地方放置配置文件?目前我在 res 目录中创建了一个目录: res/config/configuration.properties

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

它不工作:输入流为空

您可以将其放在 assets 目录中,如 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) {
}

Properties properties = new Properties();
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open("config.properties");
properties.load(inputStream);
properties.getProperty(key);