-
Notifications
You must be signed in to change notification settings - Fork 5
05. URLUtil
晓寻遥 edited this page Nov 6, 2021
·
1 revision
URLUtil is a tool that can complete incomplete URLS.
create an object from a URL address in the form of a string.
public void url() throws Exception{
String a = "https://github.com/xiao-organization/xiaoTools/wiki/2.-StrUtil";
URL url = URLUtil.url(a);
// github.com
System.out.println(url.getAuthority());
}
standardize URL links. simply complete the address without the 「http:// header」.
public void test_normalize(){
String a = "http://github.com//xiao-organization/\\xiaoTools";
String b = URLUtil.normalize(a);
// http://github.com//xiao-organization//xiaoTools
System.out.println(b);
}
use hexadecimal notation to convert the content that needs to be converted (contents other than the ASCII code form), and add% at the beginning.
public void encode_and_decode(){
String a = "xiaoTools的图标.jpg";
String b = URLUtil.encode(a);
// xiaoTools%E7%9A%84%E5%9B%BE%E6%A0%87.jpg
System.out.println(b);
String c = URLUtil.decode(b);
// xiaoTools的图标.jpg
System.out.println(c);
}
to learn more, refer to the API documentation