工具类:
public class BsNodeReader {
static String TAG="temp";
//sys_path 为节点映射到的实际路径
public static String readConfigFile(String sys_path) {
String prop = "";// 默认值
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(sys_path));
prop = reader.readLine();
} catch (IOException e) {
Log.w(TAG, " ***ERROR*** IOException: " + e.getMessage());
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
Log.w(TAG, " ***ERROR*** finally IOException" + e.getMessage());
}
}
}
return prop;
}
}
在用到的地方调用
/**
* 获取fcc
*/
fun readFcc(): String {
return BsNodeReader.readConfigFile("sys/class/power_supply/battery/charge_full")
}