java 程序中PING IP -T 时,如果实现CMD里的Ctrl+c的操作,结束继续ping ip并输出结果?请各位大哥指点指点
packagetest;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.Inpu...
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test6 {
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args){
BufferedReader reader = null;
try {
Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("ping 127.0.0.1 -t");
InputStreamReader in = new InputStreamReader(
process.getInputStream());
reader = new BufferedReader(in);
String line = "";
int num=0;
while ((line = reader.readLine()) != null) {
if(num++==5){
}
System.out.println(line);
}
} catch (IOException e) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(1);
}
}
} 展开
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test6 {
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args){
BufferedReader reader = null;
try {
Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("ping 127.0.0.1 -t");
InputStreamReader in = new InputStreamReader(
process.getInputStream());
reader = new BufferedReader(in);
String line = "";
int num=0;
while ((line = reader.readLine()) != null) {
if(num++==5){
}
System.out.println(line);
}
} catch (IOException e) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(1);
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询