问题描述
有人可以帮助解析网址吗?
我有如下网址-
实际-https://www.facebook.com/group.php/gid=12345
期待-facebook /group.php/gid=12345
实际-https://www.Test.this.domain/testPath/
期待-https wwwtestthisdomain testpath
解决方法
您可以像下面这样使用java.net.URI
:
URI uri = URI.create("https://www.facebook.com/group.php/gid=12345");
System.out.println(
uri.getPath() // prints: /group.php/gid=12345
);
System.out.println(
uri.getHost() // www.facebook.com
);