private String readSysfs(String path) {
if (!new File(path).exists()) {
Log.d(TAG, "readSysfs File not found: " + path);
return null;
}
String str = null;
StringBuilder value = new StringBuilder();
try {
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
try {
while ((str = br.readLine()) != null) {
if(str != null)
value.append(str);
};
fr.close();
br.close();
Log.d(TAG, "readSysfs value: " + value.toString());
return value.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
private boolean writeSysfs(String path, String value) {
Log.d(TAG, "writeSysfs path: " + path + " value: " + value);
if (!new File(path).exists()) {
Log.d(TAG, "writeSysfs File not found: " + path);
return false;
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(path), 64);
try {
writer.write(value);
} finally {
writer.close();
}
return true;
} catch (IOException e) {
Log.d(TAG, "IO Exception when write: " + e);
return false;
}
}