zoukankan      html  css  js  c++  java
  • Android点滴(1) 执行Linux命令并且获得输出的结果

     String cmd = "ls"; //命令

            //Runtime对象

            Runtime runtime = Runtime.getRuntime();

            try {

                //执行命令,并且获得Process对象

                      Process process = runtime.exec(cmd);

                      //获得结果的输入流

                      InputStream input = process.getInputStream();

                      BufferedReader br = new BufferedReader(new InputStreamReader(input));

                      String strLine;

                      while(null != (strLine = br.readLine())){

                            System.out.println(strLine);

                      }

                     

             } catch (IOException e) {

                     e.printStackTrace();

             }

     运行后将在LogCat中打印出 >ls 命令的结果。

    注:有的命令需要Root权限,如果权限不足或有异常出现。

  • 相关阅读:
    轻院:2211: 小明的有趣回文数
    轻院:2209: 小明找整数
    轻院:2206: 小明发福利
    轻院:2207: 小明被提问
    2135: 这里是天堂!
    牛客小白月赛2:文
    轻院2261: flower
    问题 I: 堆
    SharePoint Server 2010安装图解
    Microsoft Windows Sharepoint Services V3.0 安装图示
  • 原文地址:https://www.cnblogs.com/cody1988/p/2181565.html
Copyright © 2011-2022 走看看