// 执行命令并且输出结果 private String execRootCmd(String cmd) { Log.d(TAG, "cmd: " + cmd); String result = ""; DataOutputStream dos = null; DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec("su");// 经过Root处理的android系统即有su命令 dos = new DataOutputStream(p.getOutputStream()); dis = new DataInputStream(p.getInputStream()); dos.writeBytes(cmd + "\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); String line = ""; BufferedReader din = new BufferedReader(new InputStreamReader(dis)); while ((line = din.readLine()) != null) { Log.d(TAG, line); result += line; } Log.d(TAG, "end"); p.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } if (dis != null) { try { dis.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }