You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

16 lines
462 B

import java.net.MalformedURLException;
import java.net.URL;
public class UrlValidator {
public static void validateUrl(String urlStr) {
if (urlStr == null || urlStr.trim().isEmpty()) {
throw new UrlFormatException("URL不能为空", urlStr);
}
try {
new URL(urlStr);
} catch (MalformedURLException e) {
throw new UrlFormatException("URL格式无效", e, urlStr);
}
}
}