Java网络编程详解(No.18)
1、网络编程的目的(Purpose Of Network Programming)
? 网络编程的目的主要就是“实现不同网络设备之间的资源共享与信息传递”。
2、网络编程的要素(Elements Of network Programming)
2.1、网络通信地址(Network Communication Address)
? 即,“IP地址与端口号(如:192.168.1.1:8080)”,可准确定位到网络上一台或多台主机。
2.2、网络通信协议(Network Communication Protocol)
? 即,“TCP或者UDP”,可在定位到指定网络主机后决定如何通信。
3、IP地址(Internet Protocol Address)
3.1、本地主机(Local Host)
? 本地主机(即,本机,localhost)IP地址:“127.0.0.1”。
3.2、分类(Classification)
-
3.2.1、IPV4(Internet Protocol Version 4) 4个字节(即,4个无符号的十进制整数,每个整数取值范围0~255),总长度32位(即,32bit),总数量为”2^32“,如:”103.235.46.39“。
- 3.2.1.1、公网(Public Network,亦即”互联网“)
- 3.2.1.2、私网(Private Network,亦即”局域网“)
- 专给组织内部使用的IP地址(如:”192.168.0.123“)。
-
3.2.2、IPV6(Internet Protocol Version 6) 16个字节(即,8个无符号的十六进制整数,每个整数取值范围0000~FFFF),总长度128位(即,128bit),总数量为”2^128“,如:”1111:3333:5555:7777:9999:BBBB:DDDD:FFFF“。
3.3、域名(Domain Name)
? 即,“网域名称”,IP地址与域名是一对多的关系。一个IP地址可以对应多个域名,但是一个域名只有一个IP地址。如:”www.baidu.com“。
3.4、InetAddress类(InetAddress Class)
3.4.1、示例代码(Sample Code)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressClass {
public static void main(String[] args) {
try {
InetAddress inetAddress0=InetAddress.getByName("");
System.out.println("inetAddress0 = " + inetAddress0);
InetAddress inetAddress1=InetAddress.getByName("127.0.0.1");
System.out.println("inetAddress1 = " + inetAddress1);
InetAddress inetAddress2=InetAddress.getByName("localhost");
System.out.println("inetAddress2 = " + inetAddress2);
InetAddress inetAddress3=InetAddress.getLocalHost();
System.out.println("inetAddress3 = " + inetAddress3);
InetAddress inetAddress4=InetAddress.getByName("www.baidu.com");
System.out.println("inetAddress4 = " + inetAddress4);
System.out.println("inetAddress4.getAddress() = " + inetAddress4.getAddress());
System.out.println("inetAddress4.getCanonicalHostName() = " + inetAddress4.getCanonicalHostName());
System.out.println("inetAddress4.getHostAddress() = " + inetAddress4.getHostAddress());
System.out.println("inetAddress4.getHostName() = " + inetAddress4.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
3.4.2、运行结果(Run Result)。
? 其运行结果,如下所示。
inetAddress0 = localhost/127.0.0.1
inetAddress1 = /127.0.0.1
inetAddress2 = localhost/127.0.0.1
inetAddress3 = PC2004/10.30.90.78
inetAddress4 = www.baidu.com/14.215.177.39
inetAddress4.getAddress() = [B@4f3f5b24
inetAddress4.getCanonicalHostName() = 14.215.177.39
inetAddress4.getHostAddress() = 14.215.177.39
inetAddress4.getHostName() = www.baidu.com
4、端口号(Port Number)
? 端口号代表计算机上一个程序的进程,且不同程序的进程端口号不同。
4.1、端口号范围(Port Number Range)
? 端口号取值范围“0~65535”,且同一协议下,端口号不能冲突(即不能相同),而不同协议下,端口号可以相同(如“TCP端口为123,UDP端口也可以为123 ”)。
4.2、端口号分类(Port Number Classification)
4.3、查看端口相关信息的DOS命令(DOS Command Of View Port Related Information)
netstat -ano
netstat -ano|findstr "5396"
tasklist|findstr "5056"
4.4、InetSocketAddress类(InetSocketAddress Class)
4.4.1、示例代码(Sample Code)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
public class InetSocketAddressClass {
public static void main(String[] args) throws UnknownHostException {
InetSocketAddress inetSocketAddress1=new InetSocketAddress("127.0.0.1",8080);
InetSocketAddress inetSocketAddress2=new InetSocketAddress("localhost",8080);
InetSocketAddress inetSocketAddress3=new InetSocketAddress(InetAddress.getByName("127.0.0.1"),8080);
InetSocketAddress inetSocketAddress4=new InetSocketAddress(InetAddress.getByName("localhost"),8080);
System.out.println("inetSocketAddress1 = " + inetSocketAddress1);
System.out.println("inetSocketAddress2 = " + inetSocketAddress2);
System.out.println("inetSocketAddress3 = " + inetSocketAddress3);
System.out.println("inetSocketAddress4 = " + inetSocketAddress4);
System.out.println("inetSocketAddress1.getAddress() = " + inetSocketAddress1.getAddress());
System.out.println("inetSocketAddress1.getHostName() = " + inetSocketAddress1.getHostName());
System.out.println("inetSocketAddress1.getPort() = " + inetSocketAddress1.getPort());
}
}
4.4.2、运行结果(Run Result)。
? 其运行结果,如下所示。
inetSocketAddress1 = /127.0.0.1:8080
inetSocketAddress2 = localhost/127.0.0.1:8080
inetSocketAddress3 = /127.0.0.1:8080
inetSocketAddress4 = localhost/127.0.0.1:8080
inetSocketAddress1.getAddress() = /127.0.0.1
inetSocketAddress1.getHostName() = 127.0.0.1
inetSocketAddress1.getPort() = 8080
5、通讯协议(Communication Protocol)
5.1、OSI七层模型与TCP/IP四层模型对应关系(Relation Between OSI Seven Layer Model And TCP/IP Four Layer Model)
? OSI七层模型与TCP/IP四层模型对应关系,如下表所示。
OSI七层模型 | TCP/IP四层模型 | 相关协议 |
---|
应用层(Application Layer) | 应用层(Application Layer) | HTTP(Hyper Text Transfer Protocol,超文本传输协议)、HTTPS(Hyper Text Transfer Protocol Over SecureSocket Layer,在安全套接字层之上的超文本传输协议,即“超文本传输安全协议”)、DHCP(Dynamic Host COnfiguration Protocol,动态主机配置协议)、FTP(File Transfer Protocol,文件传输协议)、TFTP(Trivial File Transfer Protocol,简单(普通)文件传输协议)、SMTP(Simple Mail Transfer Protocol,简单邮件传输协议)、POP3(Post Office Protocol-Version 3,邮局协议版本3)、IMAP4(Internet Message Access Protocol 4,第四版因特网信息存取协议)、SSL(Secure Sockets Layer,安全套接字层,即“安全套接字协议”)、TLS(Transport Layer Security,传输层安全,即“传输安全协议”) | 表示层(Presentation Layer) | Telnet(远程终端协议)、SNMP(Simple Network Management Protocol,简单网络管理协议) | 会话层(Session Layer) | DNS(Domain Name System,网域名称系统,即“域名系统”) | 传输层(Transport Layer) | 传输层(Transport Layer) | TCP(Transmission Control Protocol,传输控制协议)、UDP(User Datagram Protocol,用户数据报协议) | 网络层(Network Layer) | 网络层(Network Layer) | IP(Internet Protocol,网际互联协议,即“互联网协议”)、ICMP(Internet Control Message Protocol,互联网控制报文协议)、ARP(Address Resolution Protocol,地址解析协议)、RARP(Reverse Address Resolution Protocol,反向地址解析协议,即“反向地址转换协议”) | 数据链路层(Data Link Layer) | 数据链路层(Data Link Layer) | FDDI(Fiber Distributed Data Interface,光纤分布式数据接口)、Ethernet(以太网)、PDN(Public Data Network,公用数据网)、SLIP(Serial Line Internet Protocol,串行线路互联网协议) | 物理层(Physical Layer) | EIA/TIA RS-232、RJ-45、IEEE 802.1A、IEEE 802.2、IEEE 802.11 |
5.2、TCP(Transmission Control Protocol,传输控制协议)
? 使用TCP协议通信(如“打电话”),其特点如下所示。
-
5.2.1、需要连接,且连接稳定。
-
5.2.2、需要明确的客户端与服务端。 -
5.2.3、只有传输完成后才会释放连接,效率低。
5.3、UDP(User Datagram Protocol,用户数据报协议)
? 使用UDP协议通信(如“发短信”),其特点如下所示。
- 5.3.1、不需要连接,且连接不稳定。
- 5.3.2、客户端与服务端没有明确的界限,一般称为“发送端和接收端”。
6、基于TCP通信协议的文字聊天的实现(Implementation Of Text Chat Based On TCP Communication Protocol)
6.1、示例代码(Sample Code)。
? 其示例代码,如下所示。
6.1.1、客户端(Client)。
package com.xueshanxuehai.networkprogramming.tcp;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class TextChatClient {
public static void main(String[] args) {
Socket socket = null;
OutputStream outputStream = null;
try {
InetAddress serverIP = InetAddress.getByName("127.0.0.1");
int serverPort = 12345;
socket = new Socket(serverIP, serverPort);
outputStream = socket.getOutputStream();
String myTCPClientStr = "Hello!TCP!";
outputStream.write(myTCPClientStr.getBytes());
System.out.println("TCP文字聊天客户端已发送信息:" + myTCPClientStr);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
6.1.2、服务器(Server)。
package com.xueshanxuehai.networkprogramming.tcp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class TextChatServer {
public static void main(String[] args) {
ServerSocket serverSocket=null;
Socket socket=null;
InputStream inputStream=null;
ByteArrayOutputStream byteArrayOutputStream=null;
try {
serverSocket=new ServerSocket(12345);
socket=serverSocket.accept();
inputStream = socket.getInputStream();
byteArrayOutputStream=new ByteArrayOutputStream();
byte[] bytes=new byte[1<<6];
int len;
while((len=(inputStream.read(bytes)))!=-1){
byteArrayOutputStream.write(bytes,0,len);
}
System.out.println("TCP文字聊天服务器已接收信息:"+byteArrayOutputStream.toString());
} catch (IOException e) {
e.printStackTrace();
}finally {
if(byteArrayOutputStream!=null){
try {
byteArrayOutputStream.flush();
byteArrayOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(socket!=null){
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(serverSocket!=null){
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
6.2、运行结果(Run Result)。
? 其运行结果,如下所示。
6.2.1、客户端(Client)。
TCP文字聊天客户端已发送信息:Hello!TCP!
6.2.2、服务器(Server)。
TCP文字聊天服务器已接收信息:Hello!TCP!
7、基于TCP通信协议的文件上传的实现(Implementation Of File Upload Based On TCP Communication Protocol)
7.1、示例代码(Sample Code)**。
? 其示例代码,如下所示。
7.1.1、客户端(Client)。
package com.xueshanxuehai.networkprogramming.tcp;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class FileUploadClient {
public static void main(String[] args) throws Exception {
Socket socket=new Socket(InetAddress.getByName("localhost"),12321);
OutputStream outputStream=socket.getOutputStream();
String filePathName="E:\\Environment\\Java\\IDEA\\StageOne\\javase\\resources\\1.png";
FileInputStream fileInputStream=new FileInputStream(new File(filePathName));
byte[] buffer1=new byte[1<<6];
int len1;
while((len1=(fileInputStream.read(buffer1)))!=-1){
outputStream.write(buffer1,0,len1);
}
System.out.println("TCP客户端已上传文件:" + filePathName);
socket.shutdownOutput();
InputStream inputStream=socket.getInputStream();
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
byte[] buffer2=new byte[1<<6];
int len2;
while((len2=(inputStream.read(buffer2)))!=-1){
byteArrayOutputStream.write(buffer2,0,len2);
}
System.out.println("TCP客户端已接收服务器反馈信息:" + byteArrayOutputStream.toString());
byteArrayOutputStream.flush();
byteArrayOutputStream.close();
inputStream.close();
fileInputStream.close();
outputStream.flush();
outputStream.close();
socket.close();
}
}
7.1.2、服务器(Server)。
package com.xueshanxuehai.networkprogramming.tcp;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class FileUploadServer {
public static void main(String[] args) throws Exception {
ServerSocket serverSocket=new ServerSocket(12321);
Socket socket=serverSocket.accept();
InputStream inputStream=socket.getInputStream();
String filePathName="E:\\Environment\\Java\\IDEA\\StageOne\\javase\\resources\\1_output.png";
FileOutputStream fileOutputStream=new FileOutputStream(new File(filePathName));
byte[] buffer=new byte[1<<6];
int len;
while((len=(inputStream.read(buffer)))!=-1){
fileOutputStream.write(buffer,0,len);
}
System.out.println("TCP服务器已上传文件:" + filePathName);
OutputStream outputStream=socket.getOutputStream();
String outputStreamStr="服务器已接收完成";
outputStream.write(outputStreamStr.getBytes());
System.out.println("TCP服务器已反馈客户端信息:"+outputStreamStr);
outputStream.flush();
outputStream.close();
fileOutputStream.flush();
fileOutputStream.close();
inputStream.close();
socket.close();
serverSocket.close();
}
}
7.2、运行结果(Run Result)。
? 其运行结果,如下所示。
7.2.1、客户端(Client)。
TCP客户端已上传文件:E:\Environment\Java\IDEA\StageOne\javase\resources\1.png
TCP客户端已接收服务器反馈信息:服务器已接收完成
7.2.2、服务器(Server)。
TCP服务器已上传文件:E:\Environment\Java\IDEA\StageOne\javase\resources\1_output.png
TCP服务器已反馈客户端信息:服务器已接收完成
8、基于UDP通信协议的消息发送与接收的实现(Implementation Of Message Send And Receive Based On UDP Communication Protocol)
8.1、示例代码(Sample Code)。
8.1.1、发送端(Sender)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
public class MessageSender {
public static void main(String[] args) throws Exception {
DatagramSocket datagramSocket=new DatagramSocket();
InetAddress inetAddress=InetAddress.getByName("localhost");
int port=12345;
String str="消息发送端";
DatagramPacket datagramPacket=new DatagramPacket(str.getBytes(),0,str.getBytes().length,new InetSocketAddress(inetAddress,port));
datagramSocket.send(datagramPacket);
System.out.println("已发送消息");
datagramSocket.close();
}
}
8.1.2、接收端(Receiver)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class MessageReceiver {
public static void main(String[] args) throws Exception {
DatagramSocket datagramSocket=new DatagramSocket(12345);
byte[] buffer = new byte[1 << 6];
DatagramPacket datagramPacket=new DatagramPacket(buffer,0,buffer.length);
datagramSocket.receive(datagramPacket);
System.out.println("已接收消息");
System.out.println(datagramPacket.getAddress());
System.out.println(new String(datagramPacket.getData(), 0, datagramPacket.getLength()));
datagramSocket.close();
}
}
8.2、运行结果(Run Result)。
8.2.1、发送端(Sender)。
? 其运行结果,如下所示。
已发送消息
8.2.2、接收端(Receiver)。
? 其运行结果,如下所示。
已接收消息
/127.0.0.1
消息发送端
9、基于UDP通信协议的文字聊天的实现(Implementation Of Text Chat Based On UDP Communication Protocol)
9.1、示例代码(Sample Code)。
9.1.1、发送端(Sender)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
public class TextChatSender {
public static void main(String[] args) throws Exception {
DatagramSocket datagramSocket=new DatagramSocket();
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
for (;;){
String str=bufferedReader.readLine();
byte[] buffer=str.getBytes();
DatagramPacket datagramPacket=new DatagramPacket(buffer,0,buffer.length,new InetSocketAddress("localhost",12345));
datagramSocket.send(datagramPacket);
System.out.println("已发送消息:"+str);
if(str.equals("end")){
break;
}
}
bufferedReader.close();
datagramSocket.close();
}
}
9.1.2、接收端(Receiver)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class TextChatReceiver {
public static void main(String[] args) throws Exception {
DatagramSocket datagramSocket = new DatagramSocket(12345);
for (; ; ) {
byte[] buffer = new byte[1 << 6];
DatagramPacket datagramPacket = new DatagramPacket(buffer, 0, buffer.length);
datagramSocket.receive(datagramPacket);
String str = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
System.out.println("已接收消息:" +str);
if(str.equals("end")){
break;
}
}
datagramSocket.close();
}
}
9.2、运行结果(Run Result)。
9.2.1、发送端(Sender)。
? 其运行结果,如下所示。
123
已发送消息:123
学习Java
已发送消息:学习Java
end
已发送消息:end
9.2.2、接收端(Receiver)。
? 其运行结果,如下所示。
已接收消息:123
已接收消息:学习Java
已接收消息:end
10、基于UDP通信协议的多线程在线咨询的实现(Implementation Of Multi-Thread Online Consultation Based On UDP Communication Protocol)
10.1、示例代码(Sample Code)。
- 10.1.1、OnLineConsultationSender类。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
public class OnLineConsultationSender implements Runnable{
DatagramSocket datagramSocket=null;
BufferedReader bufferedReader=null;
private int fromPort;
private String toIP;
private int toPort;
public OnLineConsultationSender(int fromPort, String toIP, int toPort) {
this.fromPort = fromPort;
this.toIP = toIP;
this.toPort = toPort;
try {
datagramSocket=new DatagramSocket(this.fromPort);
bufferedReader=new BufferedReader(new InputStreamReader(System.in));
} catch (SocketException e) {
e.printStackTrace();
}
}
@Override
public void run() {
for (;;){
try {
String str= bufferedReader.readLine();
byte[] buffer=str.getBytes();
DatagramPacket datagramPacket=new DatagramPacket(buffer,0,buffer.length,new InetSocketAddress(this.toIP,this.toPort));
datagramSocket.send(datagramPacket);
if(str.equals("再见")){
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bufferedReader.close();
datagramSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- 10.1.2、OnlineConsultationReceiver类。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
public class OnlineConsultationReceiver implements Runnable{
DatagramSocket datagramSocket=null;
private int fromPort;
private String fromMsg;
public OnlineConsultationReceiver(int fromPort, String fromMsg) {
this.fromPort = fromPort;
this.fromMsg = fromMsg;
try {
datagramSocket = new DatagramSocket(this.fromPort);
} catch (SocketException e) {
e.printStackTrace();
}
}
@Override
public void run() {
for (; ; ) {
try {
byte[] buffer = new byte[1 << 6];
DatagramPacket datagramPacket = new DatagramPacket(buffer, 0, buffer.length);
datagramSocket.receive(datagramPacket);
String str = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
System.out.println(this.fromMsg+":" +str);
if(str.equals("再见")){
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
datagramSocket.close();
}
}
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
public class Student {
public static void main(String[] args) {
new Thread(new OnLineConsultationSender(1111,"localhost",1221)).start();
new Thread(new OnlineConsultationReceiver(2112,"教师")).start();
}
}
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.udp;
public class Teacher {
public static void main(String[] args) {
new Thread(new OnLineConsultationSender(2222,"localhost",2112)).start();
new Thread(new OnlineConsultationReceiver(1221,"学生")).start();
}
}
10.2、运行结果(Run Result)。
10.2.1、Student类。
? 其运行结果,如下所示。
老师!请问如何学好Java?
教师:打好基础,坚持不懈!
好的,谢谢!
教师:不用谢!
再见
教师:再见
10.2.2、Teacher类。
? 其运行结果,如下所示。
学生:老师!请问如何学好Java?
打好基础,坚持不懈!
学生:好的,谢谢!
不用谢!
学生:再见
再见
11、基于URL的网络资源下载的实现(Implementation Of Download Network Resources Based On URL)
? URL(Uniform Resource Locator,统一资源定位符)就是指“网络地址”,亦即,互联网上用于指定信息位置的表示方法。
11.1、示例代码(Sample Code)。
? 其示例代码,如下所示。
package com.xueshanxuehai.networkprogramming.url;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
public class DownloadNetworkResources {
public static void main(String[] args) throws Exception {
URL url=new URL("https://p1.music.126.net/KS0TddHKX8c3atG3CkmdUw==/109951166264542938.jpg?param=200y200");
System.out.println("url.getProtocol() = " + url.getProtocol());
System.out.println("url.getHost() = " + url.getHost());
System.out.println("url.getPort() = " + url.getPort());
System.out.println("url.getPath() = " + url.getPath());
System.out.println("url.getFile() = " + url.getFile());
System.out.println("url.getQuery() = " + url.getQuery());
HttpURLConnection httpURLConnection= (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("10.30.90.55",908)));
InputStream inputStream=httpURLConnection.getInputStream();
FileOutputStream fileOutputStream=new FileOutputStream("URLTest.jpg");
byte[] buffer=new byte[1<<6];
int len;
while((len=(inputStream.read(buffer)))!=-1){
fileOutputStream.write(buffer,0,len);
}
fileOutputStream.flush();
fileOutputStream.close();
inputStream.close();
httpURLConnection.disconnect();
}
}
11.2、运行结果(Run Result)。
? 其运行结果,如下所示。
url.getProtocol() = https
url.getHost() = p1.music.126.net
url.getPort() = -1
url.getPath() = /KS0TddHKX8c3atG3CkmdUw==/109951166264542938.jpg
url.getFile() = /KS0TddHKX8c3atG3CkmdUw==/109951166264542938.jpg?param=200y200
url.getQuery() = param=200y200
参考资料(Reference Data):
学习网站地址(即"学习网址",Learning Website Address):Java网络编程详解
|