Android ping命令 -- Runtime
生活随笔
收集整理的這篇文章主要介紹了
Android ping命令 -- Runtime
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
1 public String Run(String _strsIp) throws Exception 2 { 3 String strRst = ""; 4 try 5 { 6 String str = "ping -c 1 "+_strsIp; 7 Runtime runtime = Runtime.getRuntime(); 8 Process process = runtime.exec(str); 9 10 //等待進程執(zhí)行完畢 11 if(process.waitFor() != 0) 12 { 13 //如果進程運行結果不為0,表示進程是錯誤退出的 14 //獲得進程實例的錯誤輸出 15 InputStream streamErr = process.getErrorStream(); 16 //do something 17 18 strRst = InputStream2String(streamErr); 19 if (streamErr != null) 20 streamErr.close(); 21 22 if (strRst.isEmpty()) 23 { 24 InputStream streamIn = process.getInputStream(); 25 strRst = InputStream2String(streamIn); 26 if (streamIn != null) 27 streamIn.close(); 28 29 if (strRst.isEmpty()) 30 strRst = "Failed : ping failed . "; 31 } 32 return strRst; 33 } 34 35 InputStream streamIn = process.getInputStream(); 36 strRst = InputStream2String(streamIn); 37 if (streamIn != null) 38 streamIn.close(); 39 40 if (strRst.isEmpty()) 41 strRst = "Succeed : ping failed . "; 42 } 43 catch (Exception ex) 44 { 45 //ex.printStackTrace(); 46 StringWriter sw = new StringWriter(); 47 PrintWriter pw = new PrintWriter(sw); 48 ex.printStackTrace(pw); 49 strRst = "Err : "+sw.toString(); 50 } 51 return strRst; 52 }?
轉載于:https://www.cnblogs.com/codeskilla/p/4953117.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Android ping命令 -- Runtime的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 记录自己Kettle下载全过程
- 下一篇: Android Studio开发环境搭建