繁体   English   中英

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"));

它不起作用:输入流为空

您可以将其作为资产/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配置文件

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM