java 在 Android 中加载属性文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17096167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:57:28  来源:igfitidea点击:

Loading Properties File in Android

javaandroidfilepropertiesload

提问by user2154477

I have a properties file in my android project but I don't know how to read properties from the file. I have seen several tutorials but those did not help me, in addition I am getting some errors. Would you please post some simple example code to understand how this works?

我的 android 项目中有一个属性文件,但我不知道如何从文件中读取属性。我看过几个教程,但这些都没有帮助我,此外我还遇到了一些错误。您能否发布一些简单的示例代码来了解这是如何工作的?

回答by PandaBearSoup

Here is some example code...

这是一些示例代码...

Properties props=new Properties();
InputStream inputStream = 
this.getClass().getClassLoader().getResourceAsStream("example.properties");
props.load(inputStream);
exampleUrl=props.getProperty("baseUrl");
exampleUsername=props.getProperty("username");      
examplepassword=props.getProperty("password");

can not help much more without some of your own code. Hope this helps.

如果没有您自己的一些代码,将无济于事。希望这可以帮助。