How to Validate a URL Using Java

Veröffentlicht am: 28 Dezember 2021
auf dem Kanal: Max O'Didily
1,407
20

How to Validate a URL Using Java

Greetings, I am back with another tutorial and today I am here with how validate a URL(Uniform Resource Locator). We can do this by attempting to create a URL object and parsing in string input containing the URL we wish to validate. A try catch statment can be used, if an error occurs, return a false, if no error occurs, return a true. Thanks for watching and have a spectacular day.

Subscribe to keep notified when I upload:
https://tinyurl.com/SubMaxODidily

Source code:

import java.net.URL;

public class CheckURLIsValid {

/**
@param args the command line arguments
*/

public static boolean validateURL(String urlString)
{
try
{
new URL(urlString).toURI();
}
catch (Exception e)
{
System.out.println(e);
return false;
}

return true;
}

public static void main(String[] args) {

String link = "bob";

System.out.println(validateURL(link));
}
}

How to Validate a URL Using Java


Auf dieser Seite können Sie das Online-Video How to Validate a URL Using Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Max O'Didily 28 Dezember 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,407 Mal angesehen und es wurde von 20 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!