【发布时间】:2014-07-28 11:27:17
【问题描述】:
我编写了一个类来 ping 我提供的 IP 地址,但它不会返回任何内容。 我尝试添加一些标记以查看哪里出错了,但即使这样也没有用... 我有一个 gui 界面,我使用一个标签来写出我的数据(以前使用字符串的相同格式),这里是代码。我想要或不想要某些行,因此“相关”整数,您可以忽略它。这应该在 ubuntu 13.10 上运行。
public static ArrayList<String> PingIpAddr(String string) throws IOException{
String s = new String();
int relevant =0;
ArrayList<String> List = new ArrayList<String>();
List.add("it happens \n");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(new ProcessBuilder(string).start().getInputStream()));
while ((s = stdInput.readLine()) != null){
List.add("does this happen? \n");
relevant++;
if( (relevant == 2) || (relevant == 3) || (relevant == 4) || (relevant == 5) || (relevant == 6) || (relevant == 9) ){List.add(s + "\n");
List.add("or this? \n");}} //end of while
List.add("This must happen! \n");
return List;} //end of Ping
如果这行得通,这里就是实施它的地方:
String test;
test = PingIp.testPingIpAddr("ping -c 5 4.2.2.2").toString();
TeltonikaPing.setWrapText(true);
TeltonikaPing.setText(test);
奇怪的是它没有返回一行。也许我只是错过了一些非常基本的东西?:/
【问题讨论】:
标签: java user-interface javafx ping