Friday, 22 May 2020
how to check url is valid or not in java
import java.net.URL;
import java.util.Scanner;
class URLTest {
//static method to validate URL
public static boolean isValid(String url){
try{
new URL(url).toURI();
return true;
}catch(Exception e){
//if exception generate than return false
return false;
}
}
public static void main(String[] args)
{
// user URL input
System.out.print("Enter URL: ");
Scanner sc = new Scanner(System.in);
String url = sc.nextLine();
//now check by method
if(isValid(url)){
System.out.print("\nYes URL is Valid ");
}else{
System.out.print("\n No URL is Not Valid ");
}
}
}
Subscribe to:
Post Comments (Atom)
-
/* action perform event for insert data into table Database : student_info Table : class5 root username of mysql db mysql@123 is a pas...
-
index.html <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8...
-
private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) { // TODO add your han...
No comments:
Post a Comment