Base64编码和解码

来源:互联网 发布:哈尔滨软件开发bcweb 编辑:程序博客网 时间:2024/05/29 19:31

使用jdk自带jar

package demo;import java.io.IOException;import java.io.UnsupportedEncodingException;import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder;public class Base64EncodeAndDecode {public static void main(String[] args) {String temp = "你好,我叫tom";BASE64Encoder encoder = new BASE64Encoder();BASE64Decoder decoder = new BASE64Decoder();try {temp = encoder.encode(temp.getBytes("utf-8"));System.out.println(temp);byte[] tempByte = decoder.decodeBuffer(temp);temp = new String(tempByte, "utf-8");System.out.println(temp);} catch (UnsupportedEncodingException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}


原创粉丝点击