标签:style blog color io java strong sp div on
收集编码与解码
base64
//编码 sun.misc.BASE64Decoder @Test public void t9(){ BASE64Encoder encoder = new BASE64Encoder() ; String r = "" ; try { r = encoder.encode("中国".getBytes("utf-8")) ; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println(r); //5Lit5Zu9 } //解码sun.misc.BASE64Decoder @Test public void t10(){ BASE64Decoder decoder = new BASE64Decoder() ; String r = "" ; try { r = new String(decoder.decodeBuffer("5Lit5Zu9"), "utf-8") ; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println(r);//中国 }
url
//编码java.net.URLEncoder @Test public void t11(){ String r = "" ; try { r = URLEncoder.encode("中国", "utf-8") ; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println(r); //%E4%B8%AD%E5%9B%BD } //解码java.net.URLDecoder @Test public void t12(){ String r = "" ; try { r = URLDecoder.decode("%E4%B8%AD%E5%9B%BD", "utf-8") ; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println(r);//中国 }
标签:style blog color io java strong sp div on
原文地址:http://www.cnblogs.com/ooi-/p/4028913.html