Online Java Compiler By
JavaTpoint.com
import java.net.*; class URLgetUserInfoExample1 { public static String encodeURL(String urlString) { String encodedUrl=null; try { URL url=new URL(urlString); URI uri= new URI(url.getProtocol(),url.getUserInfo(),url.getHost(),url.getPort(),url.getPath(), url.getQuery(),url.getRef()); System.out.println("user information is :"+url.getUserInfo()); encodedUrl=uri.toURL().toString(); } catch (Exception exc) { return null; } return encodedUrl; } public static void main(String arg[]) { URLgetUserInfoExample1 u=new URLgetUserInfoExample1(); System.out.println(" "+u.encodeURL("https://mail.google.com/mail/u/0/?tab=wm#inbox")); } }
Output