背景
功能:读取/vendor/etc/locale.cfg文件中的属性值。例如读取文件中ro.product.tv.country.list=EU_AU行。
用例:
String countryListString = readLocaleCfgProperty("ro.product.tv.country.list");
//读取/vendor/etc/locale.cfg文件中的属性值。例如读取文件中ro.product.tv.country.list=EU_AU行
private String readLocaleCfgProperty(String propertyName) {
File file = new File("/vendor/etc/locale.cfg");
if (!file.exists()) {
return null;
}
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith(propertyName)) {
String[] keyValue = line.split("=");
if (keyValue.length == 2) {
String value = keyValue[1].trim();
Log.d(TAG, "readLocaleCfgProperty, " + propertyName + "=" + value);
return value;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}