p = Runtime.getRuntime().exec("ping -c 4 -w 20 " + serverIp);
int status = p.waitFor();
if (status == 0) {
BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream()));
String str = new String();
while ((str = buf.readLine()) != null) {
if (str.contains("avg")) {
int i = str.indexOf("/", 20);
int j = str.indexOf(".", i);
delay = str.substring(i + 1, j);
}
}
Log.d("look_fps", delay);
}
android获取ping IP的fps
最新推荐文章于 2025-09-16 00:15:00 发布
本文介绍了一种使用Java运行时环境执行Ping命令并解析其响应的方法。通过Runtime.getRuntime().exec()函数执行Ping命令,然后利用BufferedReader读取命令的输出流,从中筛选包含avg关键字的行,进一步提取平均延迟时间。
1781

被折叠的 条评论
为什么被折叠?



