首页 > 代码库 > 编码与解码方法收集

编码与解码方法收集

收集编码与解码

 

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);//中国    }    

 

编码与解码方法收集