吴旭晓个人博客 繁体中文 简体中文

首页| 日志 |JAVA |ASP |PHP |Android |IOS |ASP.NET |JavaScript |DIV+CSS |SEO |taobaoke |饼哥语录
繁体中文 简体中文

Java base64 编码和解码案例

Java代码


 import java.io.IOException;
  public class test {
  /**
  * 编码
  * @param bstr
  * @return String
  */
  public static String encode(byte[] bstr){
  return new sun.misc.BASE64Encoder().encode(bstr);
  }
  /**
  * 解码
  * @param str
  * @return string
  */
  public static byte[] decode(String str){
  byte[] bt = null;
  try {
  sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
  bt = decoder.decodeBuffer( str );
  } catch (IOException e) {
  e.printStackTrace();
  }
  return bt;
  }
  /**
  * @param args
  */
  public static void main(String[] args) {
  test te = new test();
  String aa = "更多更多";
  aa = te.encode(aa.getBytes());
  System.out.println("----aa:"+aa);
  String str = aa;
  String str2 = new String(te.decode(str));
  System.out.println("-----str2:"+str2);
  }
  }

作者:吴旭晓 | 来源:个人博客 | 点击量:1599 | 发布时间:2013-06-26
最新留言 | 返回上一页 | 返回首页

相关文章:

版权所有:吴旭晓个人博客 Copyright © 2013-2023 个人博客