使用java.net.*
------解决方案--------------------
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class NetTest
{
public static void main(String[] args)
{
Socket s = null;
try
{
s = new Socket( "www.google.com ", 80);
System.out.println( "连网 ");
}
catch (UnknownHostException e)
{
System.out.println( "未连网 ");
}
catch (IOException e)
{
System.out.println( "未连网 ");
}
finally
{
try
{
if(s != null)
s.close();
}
catch (IOException e)
{
}
}
}
}