URLUtil
Introduction
URL (Uniform Resource Locator) is a Chinese name for a uniform resource locator, sometimes also commonly referred to as a web address. It represents resources on the Internet, such as web pages or FTP addresses. In Java, URLs can also be used to represent resources (Resources) addresses in the Classpath.
Methods
Obtaining URL Objects
URLUtil.urlCreates an object from a string-based URL addressURLUtil.getURLPrimarily obtains the URL of resources in the ClassPath to facilitate reading configuration files and other information in the ClassPath.
Others
URLUtil.normalizeNormalizes URL links. Simply completes addresses without http:// headers.
String url = "http://www.hutool.cn//aaa/bbb";
// Result: http://www.hutool.cn/aaa/bbb
String normalize = URLUtil.normalize(url);
url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2";
// Result: http://www.hutool.cn/aaa/bbb?a=1&b=2
normalize = URLUtil.normalize(url);URLUtil.encodeEncapsulatesURLEncoder.encode, converts the content that needs to be converted (content outside of ASCII code form) into hexadecimal representation, and prefixes it with %.
String body = "366466 - 副本.jpg";
// Result: 366466%20-%20%E5%89%AF%E6%9C%AC.jpg
String encode = URLUtil.encode(body);URLUtil.decodeEncapsulatesURLDecoder.decode, decodes hexadecimal content that starts with %.URLUtil.getPathObtains the path component URI -> http://www.aaa.bbb/search?scope=ccc&q=ddd PATH -> /searchURLUtil.toURIConverts a URL or URL string to a URI.