展开全部
简单点的直接使用Runtime的exec来搞定,如下:public static void main( String[] args )
{
StringBuffer buf = new StringBuffer();
String s = "";
Process process;
try
{
process = Runtime.getRuntime().exec( "cmd /c " + "ping 127.0.0.1" );
BufferedReader br = new BufferedReader( new InputStreamReader(
process.getInputStream() ) );
while ( ( s = br.readLine() ) != null )
{
buf.append( s + "\r\n" );
}
process.waitFor();
System.out.println( buf );
} catch ( Exception ex )
{
ex.printStackTrace();
}
}
复杂点的,可以查看Oracle的官网文档,实现了完62616964757a686964616fe59b9ee7ad9431333335306331整的ping:(粘贴下面的路径到浏览器地址栏,加上http://)
docs.oracle.com/javase/1.5.0/docs/guide/nio/example/Ping.java