URL url = new URL("https://www.example.com/index.html"); String strURL = url.toExternalForm(); System.out.println(strURL);
URL url = new URL("file:///C:/Users/user/Desktop/index.html"); String strURL = url.toExternalForm(); System.out.println(strURL);This example creates a URL object with the address "file:///C:/Users/user/Desktop/index.html" and then uses toExternalForm() to convert it to a string and print it to the console. The output will be "file:///C:/Users/user/Desktop/index.html". The java.net.URL class belongs to the java.net package library.