作者f1991930 (ㄚ緯)
看板java
標題[問題] 有個PING指令的JAVA程式碼求救
時間Fri Jun 7 22:43:20 2013
下面末端有***的程式碼是需要解釋的部分,請大家幫幫忙~
import java.io.*;
public class JavaApplication1 {
public static void main(String[] args) {
Runtime runtime = Runtime.getRuntime(); ***
Process process = null; ***
String line = null; ***
InputStream is = null; ***
InputStreamReader isr = null; ***
BufferedReader br = null; ***
String ip = "IP"; //要Ping 的IP位址
try {
process = runtime.exec("ping " + ip); ***
is = process.getInputStream(); ***
isr = new InputStreamReader(is); ***
br = new BufferedReader(isr); ***
while ( (line = br.readLine()) != null) { ***
System.out.println(line);
System.out.flush(); ***
}
is.close(); ***
isr.close(); ***
br.close(); ***
System.out.println("Java 呼叫 ping 程式,執行完畢!");
}
catch (IOException e) { ***
System.out.println(e); ***
runtime.exit(0); ***
}
}//end main method
}//end class
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.38.114.194
→ tkcn:除了有大括號的行數都有 *** 了,沒注意看還以為是新語言 06/07 22:44
→ realmeat:execute shell是邪魔歪道 06/07 22:46
推 asadman1523:我竟然都看得懂...不過原來runtime可以這樣用喔來試試 06/07 23:11
→ cuteclare:*** 都翻成 你是在註解三小啦 ~ 就ok了 06/07 23:45
推 cyclone350:第三個 *** 是說有一個 String 名為 line,值是 null 06/07 23:48
→ cyclone350:不懂2F的意思 06/08 00:02