gpt4 book ai didi

java - Android项目中的配置属性文件

转载 作者:行者123 更新时间:2023-12-02 03:59:38 26 4
gpt4 key购买 nike

Android 项目中的配置文件放在哪里?目前我在 res 目录中创建了一个目录:res/config/configuration.properties

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

它不起作用:输入流为空

最佳答案

您可以将其作为 assets/configuration.properties 放置在 assets 目录中

示例代码

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) {
}

关于java - Android项目中的配置属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com