Here you can find the source of encodePath(String str)
public static String encodePath(String str)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; import java.util.stream.Collectors; public class Main { public static String encodePath(String str) { return Arrays.stream(str.split("/")).map(s -> encode(s)).collect(Collectors.joining("/")); }//from w w w. ja va 2 s .com public static String encode(String str) { try { return URLEncoder.encode(str, "UTF-8").replace("+", "%20"); } catch (UnsupportedEncodingException e) { // cannot happen, because UTF-8 is always valid return str; } } }