如何用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
相关问答:
我想用Java写一个程序,就是我想在运行代码后,在指定的时间打开某程序,例如我运行代码后,讲在12:00打开"D:\Program Files\Tencent\QQ2009\Bin\QQ.exe"这个程序,求高人指点。还有可能的话在指定的时间 ......
在asp里怎么调用java写的webservice方法,有很多方法
- <message name="RtPnrIn">
<part name="bstrPnrNO" type="s:string" />
<part name ......
我JSP的页面是:
<%@ page language="java" contentType="text/html; charset=gb2312"
%>
<script>
function Save(){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==nul ......
代码如下 ,我想通过代理访问一些网址,但是不知道如何测试代理成功,我想通过访问“http://www.blogger.com/”来看看是否代理成功,但是也不能访问,出现异常“Unexpected end of file from server”,但是如果不这 ......