Online Java Compiler By
JavaTpoint.com
import java.net.*; class URLtoURIExample1 { public static void main(String args[]) { URL url = null; try { url = new URL("https://www.javatpoint.com/URL-class"); System.out.println("URL created: " + url); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + e.getMessage()); } try { // getting URI from url URI uri = url.toURI(); System.out.println("URI from URL: " + uri); } catch (URISyntaxException e) { System.out.println("URI Syntax Error: " + e.getMessage()); } } }
Output