如何用Java实现Ping(思路)
RT.Java code:
public class CmdTest {
private static final long serialVersionUID = -2650474785662737262L;
public static void main(String[] args) throws Exception {
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("cmd /c ping 127.0.0.1");
DealStream errStream = new DealStream(p.getErrorStream(),"Err");
DealStream outStream = new DealStream(p.getInputStream(),"Out");
new Thread(errStream).start();
new Thread(outStream).start();
int exitValue = p.waitFor();
System.out.println("exitValue -- > " + exitValue);
}
}
class DealStream implements Runnable{
private InputStream is;
private String type;
public DealStream(InputStream is,String type){
this.is = is;
this.type = type;
}
public void run(){
try{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String temp = null;
while((temp = br.readLine()) != null){
System.out.println(type + "-->" + temp + "\n");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
is.close();
}catch(Ex
相关问答:
问题描述:写日志功能,写好的写日志服务,其他用户通过http调用服务,传入参数,然后记录日志,
我的服务该怎么写, 别人怎么通过http调用我的服务,我用webservice写好了一个,可是并发有上线,想改� ......
我想用Java写一个程序,就是我想在运行代码后,在指定的时间打开某程序,例如我运行代码后,讲在12:00打开"D:\Program Files\Tencent\QQ2009\Bin\QQ.exe"这个程序,求高人指点。还有可能的话在指定的时间 ......
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class QueryTest&n ......
我定义了一个JRadioButtonNan的单选按钮,如果在我选择了这个按钮后想点击重置让这个按钮处于未选择的状态该怎么做呢?请高手指教
jRadioButton.setSelected(false);
不知道你是什么意思
这个是不选择状态了
� ......