1 URL 访问网络资源
URL url = new URL("http://www.infoq.com");
InputStream is = url.openStream();
OutputStream os = new FileOutputStream("c:/text.txt");
byte[] buffer = new byte[2048];
int leng=0;
while((leng=is.read(buffer,0,buffer.length) )!=-1){
os.write(buffer, 0 , leng);
}
is.close();
os.close();
System.out.println( "结束。。。。");
2 InetAddress 使用
public static void main(String[] args) throws UnknownHostException {
InetAddress address = InetAddress.getByName("自己机器名称");
String str = new String(address.getAddress( ));
System.out.println(address );
address = InetAddress.getByName("http://www.baidu.com");
System.out.println( address );
}