日期:2014-05-17 浏览次数:20752 次
public static void main(String[] args) throws Exception { URL url = new URL( "http://www.baidu.com"); URLConnection conn = url.openConnection(); conn.connect(); System.out.println("連接成功"); }
Exception in thread "main" java.net.UnknownHostException: www.baidu.com at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.<init>(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at com.arj.comm.util.WeatherReport.main(WeatherReport.java:131)
conn.connect();