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

标签 java android android-resources

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/

相关文章:

安卓/PhoneGap : destroy webview when going background instead of keepRunning=false

java - 从字符串中获取资源id

android - 如何获取作为属性引用的维度值?

java - 找到数组中最长的连续体,该连续体中的值的总和等于零模 3

android - 找不到以下类 : - android. support.design.widget.TextInputLayout

java - 代码示例中 Java 的正则表达式问题

安卓 : Facebook like newsfeed with multiple images and videos

java - Android中如何管理数据

java - 使用java在幻灯片中创建段落项目符号

java - 高效算法(散列、排序)