- 訪問(wèn)baidu首頁(yè)的html內(nèi)容
public class NetConnectionTest {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.baidu.com");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String res = "";
while(null!=(res = reader.readLine())){
System.out.println(res);
}
reader.close();
}
}
public class NetConnectionTest {
public static void main(String[] args) throws Exception {
InetAddress ia = InetAddress.getLocalHost();//訪問(wèn)本機(jī)
System.out.println(ia);
InetAddress baidu = InetAddress.getByName("www.baidu.com");//通過(guò)域名訪問(wèn)
System.out.println(baidu);
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者