开始想用正则,百度了下还准备用URL方法。
现有URL地址
http://www.xupt.edu.cn:8080/home/subhome/index.html
提取出其中的协议(http)、域名(www.xupt.edu.cn)、端口号(8080)、目录(/home/subhome)、和文件(index.html)。
package qwe;
public class test2 {
public static void main(String[] args) {
String url="http://www.xupt.edu.cn:8080/home/subhome/index.html";
for(String temp:url.split("://|:|/")) {
System.out.println(temp);
}
}
}