Java tutorial
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.StringTokenizer; public class Main { public static String encodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLEncoder.encode(tokenizer.nextToken(), characterSet)); builder.append(delimiter); } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); } }