我有以下代码:
String s;
String FinalS = "";
try {
Process p = Runtime.getRuntime().exec(new String[] { "su", "-c", "netstat -au"});
BufferedReader inputStream = new BufferedReader(new
InputStreamReader(p.getInputStream()));
// reading output stream of the command
while ((s = inputStream.readLine()) != null) {
//Log.d("", s);
FinalS.concat(s);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d("", FinalS);
当我在“ while”中使用“ Log.e”时,它可以正确打印,但是当我使用“ FinsalS”时,它不起作用,LogCat屏幕显示:
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/commandsnetwor: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/commandsnetwor: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
还有其他方法可以将.exec的结果仅保存在一个String中吗? 我正在使用Android 10(API级别29),并且我的设备中具有root访问权限。 感谢您的建议!