在我的应用程序中,我想执行Linux-Terminal-Commands,例如“ls”和 在EditText中显示结果。
答案 0 :(得分:0)
试试这个
try
{
Process process = Runtime.getRuntime().exec("ls");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null)
{
result.append(line + "\n");
}
EditText et = (EditText) findViewById(R.id.edittext);
et.setText(result.toString());
}
catch (IOException e)
{
throw new RuntimeException(e);
}