我正试图从代码中读取/sys/kernel/debug/tracing/trtrace文件的内容,但无法读取mount-o rw,remount-t debugfs nodev/sys/kernel/debug并做了chmod-R 777/sys/kernel/debug
File myFile = new File("/sys/kernel/debug/tracing/trace");
FileInputStream fIn = null;
try {
fIn = new FileInputStream(myFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow;
try {
while ((aDataRow = myReader.readLine()) != null) {
// Toast.makeText(getBaseContext(), aDataRow, Toast.LENGTH_LONG).show();
t.setText(aDataRow);
break;
}
} catch (IOException e) {
e.printStackTrace();
}
您需要在程序中使用"su"命令。
Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "cat /sys/kernel/debug/tracing/trace" });
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {