Here you can find the source of encodeUri(String uri)
public static String encodeUri(String uri)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.StringTokenizer; public class Main { /**//from w w w . j a va 2 s.c o m * URL-encodes everything between "/"-characters. Encodes spaces as '%20' instead of '+'. */ public static String encodeUri(String uri) { String newUri = ""; StringTokenizer st = new StringTokenizer(uri, "/ ", true); while (st.hasMoreTokens()) { String tok = st.nextToken(); if (tok.equals("/")) { newUri += "/"; } else if (tok.equals(" ")) { newUri += "%20"; } else { try { newUri += URLEncoder.encode(tok, "UTF-8"); } catch (UnsupportedEncodingException ignored) { } } } return newUri; } }