Android 如何从Project.properties或local.properties读取属性?
很抱歉问这样一个基本的问题,但我没能找到这些信息。我想从Android项目属性文件(project.properties或local.properties)中读取设置,但我运气不好。System.getProperty似乎没有用处,总是返回null。1在android项目的资产文件夹中创建一个名为subtype.properties的文件 2编辑密钥值的文件-Android 如何从Project.properties或local.properties读取属性?,android,properties,Android,Properties,很抱歉问这样一个基本的问题,但我没能找到这些信息。我想从Android项目属性文件(project.properties或local.properties)中读取设置,但我运气不好。System.getProperty似乎没有用处,总是返回null。1在android项目的资产文件夹中创建一个名为subtype.properties的文件 2编辑密钥值的文件- key=value url=www.xyz.com ..... 现在在你的活动中调用这个- Properties prop =
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;
}
改用SharedReferences.:-)