Write code to url encode
Use UTF-8 as encoding
Use URLEncoder.encode() method
//package com.book2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static void main(String[] argv) { String str = "book2s.com"; System.out.println(urlencode(str)); }/* www . j a va2 s .c om*/ public static String urlencode(String str) { try { return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } }