从URLDecoder.java复制
//package com.nowjava; /* from nowjava.com*/ import java.io.UnsupportedEncodingException; public class Main { public static void main(String[] argv) throws Exception { String s = "nowjava.com"; System.out.println(decode(s)); } /** * Copied from URLDecoder.java */ public static String decode(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { case '+': sb.append(' '); break; /**来自 nowjava.com - 时代Java**/ case '%': try { sb.append((char) Integer.parseInt( s.substring(i + 1, i + 3), 16)); } catch (NumberFormatException e) { throw new IllegalArgumentException(s); } i += 2; break; default: sb.append(c); break; } } // Undo conversion to external encoding String result = sb.toString(); try {