InetAddress 类
该类的对象用于IP地址和域名
.getByName( string s)获得一个InetAddress类的对象
String getHostName ()获得InetAddress对象的域名
String getHostAddress ()获得InetAddress对象的ip地址
getLocalHost()获得InetAddress对象,包含本地机的IP地址和域名
URL资源定位器:
一个URL对象可以表示一个网络资源
URL url=new URL(" http://www.baidu.com") 创建一个URL对象
URLConnection uc=url.openConnection();//获得URLConnection对象
例:
public void readByURL(String urlName){
try{
URL url = new URL(urlName);//由网址创建URL对象
URLConnection tc = url.openConnectin();//获得URLConnection对象
tc.connect();//设置网络连接
InptStreamReader in = new InputStreamReader(tc.getInputStream());
BufferedReader dis = new BufferedReader(in);//采用缓冲式输入
String inline;
while((inline = dis.readLine())!=null){
showArea.append(inline +”\n”);
}
dis.close();//网上资源使用结束后,数据流及时关闭
}catch(MalformedURLException e){
e.printStackTrace();
}
catch(IOException e){e.printStacktrace();}
/*访问网上资源可能产生MalformedURLException和IOException异常*/
}