1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import java.io.*;
public class JPing {
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 = "127.0.0.1";
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);
}
}
}
|