码迷,mamicode.com
首页 > 移动开发 > 详细

Android Runtime.getRuntime().exec

时间:2017-09-24 09:53:46      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:color   com   close   wait   col   har   for   new   size   

 try {  
            // Executes the command.  
            Process process = Runtime.getRuntime().exec(cmd);  
  
            // NOTE: You can write to stdin of the command using  
            // process.getOutputStream().  
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            int read;  
            char[] buffer = new char[4096];  
            StringBuffer output = new StringBuffer();  
            while ((read = reader.read(buffer)) > 0) {  
                output.append(buffer, 0, read);  
            }  
            reader.close();  
  
            // Waits for the command to finish.  
            process.waitFor();  
  
            return output.toString();  
        } catch (IOException e) {  
            throw new RuntimeException(e);  
        } catch (InterruptedException e) {  
            throw new RuntimeException(e);  
        }  
    }

 

        String mProjectName = doCommand("cat /proc/version").trim();
        Log.d(TAG, "mProjectName =" + mProjectName);

Android Runtime.getRuntime().exec

标签:color   com   close   wait   col   har   for   new   size   

原文地址:http://www.cnblogs.com/onelikeone/p/7585722.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!