try {
String str = "你好";
str = URLEncoder.encode(str, "UTF-8");
System.out.println(str);
str = URLDecoder.decode(str, "UTF-8");
System.out.println(str);
str = new String("Hello world".getBytes(), "UTF-8");
System.out.println(str);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
java.net.URLEncoder
该类包含了将 String 转换为 application/x-www-form-urlencoded
MIME 格式的静态方法encode(String s, String enc)
"UTF-8,GBK..."
java.net.URLDecoder 该类包含了将 String 从 application/x-www-form-urlencoded MIME 格式解码的静态方法。decode(String s, String enc) "UTF-8,GBK..."
String(byte[] bytes, String charsetName)
通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String。