java怎么执行ping,如何用Java实现Ping(思路)

如何用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);

不知道你是什么意思

这个是不选择状态了

� ......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值