很抱歉问这个基本问题是什么,但我没有找到这些信息。我想读取Android项目属性文件(project.properties或local.properties)中的设置,我没有运气。 System.getProperty似乎没用,总是返回null。
答案 0 :(得分:2)
1在android项目的assets文件夹中创建一个名为subtype.properties的文件
2编辑文件以获取键值 -
key=value
url=www.xyz.com
.....
现在在您的活动中调用此内容 -
Properties prop = new Properties();
try {
prop = loadPropties();
} catch (IOException e) {
Log.e(TAG, "Exception", e);
}
Log.d(TAG,"The value in prop file is " + prop.getProperty("key"));
//Write this function in your activity -
private Properties loadPropties() throws IOException {
String[] fileList = { "subtype.properties" };
Properties prop = new Properties();
for (int i = fileList.length - 1; i >= 0; i--) {
String file = fileList[i];
try {
InputStream fileStream = getAssets().open(file);
prop.load(fileStream);
fileStream.close();
} catch (FileNotFoundException e) {
Log.e(TAG , "Got exception " + e);
}
}
return prop;
}