當前位置:編程學習大全網 - 網站源碼 - Java代碼調用cmd中的ping命令.如何獲得ping返回的信息?

Java代碼調用cmd中的ping命令.如何獲得ping返回的信息?

public static void main(String[] args) throws IOException, InterruptedException {

// 執行ping命令

String cmdPing = "ping 127.0.0.1";

Runtime run = Runtime.getRuntime();

Process process = run.exec(cmdPing);

process.waitFor();

BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));

String line = null;

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

System.out.println(line);

}

}

  • 上一篇:Tesseract-OCR訓練識別驗證碼有什麽高效的辦法嗎
  • 下一篇:微信沒有提示圖標oppor815
  • copyright 2024編程學習大全網