標籤:public stack 令行 exception test 丟失 input 接收 amr
package javai;import java.io.BufferedReader;import java.io.InputStreamReader;public class IOTest { public static void main(String[] args) { try { Process pro = Runtime.getRuntime().exec("ping www.baidu.com"); String line; BufferedReader buf = new BufferedReader(new InputStreamReader(pro.getInputStream())); while ((line = buf.readLine()) != null) System.out.println(line); } catch ( Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
正在 Ping www.a.shifen.com [220.181.111.188] 具有 32 位元組的資料:
來自 220.181.111.188 的回複: 位元組=32 時間=28ms TTL=54
來自 220.181.111.188 的回複: 位元組=32 時間=28ms TTL=54
來自 220.181.111.188 的回複: 位元組=32 時間=28ms TTL=54
來自 220.181.111.188 的回複: 位元組=32 時間=28ms TTL=54
220.181.111.188 的 Ping 統計資訊:
資料包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短 = 28ms,最長 = 28ms,平均 = 28ms
java執行命令列命令