熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

java base64編碼和解碼案例

2013-11-23 19:30:25  來源: Java核心技術 

  Java代碼

  import javaioIOException;

  public class test {

  /**

  * 編碼

  * @param bstr

  * @return String

  */

  public static String encode(byte[] bstr){

  return new sunmiscBASEEncoder()encode(bstr);

  }

  /**

  * 解碼

  * @param str

  * @return string

  */

  public static byte[] decode(String str){

  byte[] bt = null;

  try {

  sunmiscBASEDecoder decoder = new sunmiscBASEDecoder();

  bt = decoderdecodeBuffer( str );

  } catch (IOException e) {

  eprintStackTrace();

  }

  return bt;

  }

  /**

  * @param args

  */

  public static void main(String[] args) {

  test te = new test();

  String aa = 更多更多;

  aa = teencode(aagetBytes());

  Systemoutprintln(aa:+aa);

  String str = aa;

  String str = new String(tedecode(str));

  Systemoutprintln(str:+str);

  }

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26998.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.