有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java计算ping时间

如何计算安卓 ip地址的延迟/ping时间(毫秒)

我想在我的应用程序中实现这一点。 我尝试了以下代码,但它没有输出任何内容

private void executeCommand() throws IOException {
    String pingResult="  ";

    Runtime r=Runtime.getRuntime();
    Process p=r.exec(new String[] {"ping", "-c 4", "www.google.com"});
    try {
        p.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String inputLine;
    Toast.makeText(getApplicationContext(), "Going loop", 1).show();
    while((inputLine=in.readLine())!=null)
    {
        pingResult+=inputLine;
    }
    Toast.makeText(getApplicationContext(),pingResult, 1).show();
    System.out.println(pingResult);
    in.close();
}

共 (1) 个答案

  1. # 1 楼答案

    已使用adb shell pingClick

    亚行没有平。 没有ping

    netstat