Here you can find the source of encodeURIComponent(String uriComp)
public static String encodeURIComponent(String uriComp)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static String encodeURIComponent(String uriComp) { try {/*from w w w. jav a 2 s . c o m*/ return URLEncoder.encode(uriComp, "UTF-8").replaceAll("\\+", "%20"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Encoding URI component \"" + uriComp + "\" failed", e); } } }