`
huzhenyu
  • 浏览: 185406 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

BASE64与字符串互转

    博客分类:
  • JAVA
阅读更多

package com.huzy.mailTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class StringToBase64 {
	
	public static void main(String[] args) throws IOException {
		encoder();
//		decoder();
	}
	
	public static void encoder() throws IOException {
		BASE64Encoder encoder = new BASE64Encoder();
		while (true) {
			System.out.println("please input your content");
			String name = new BufferedReader(new InputStreamReader(System.in)).readLine();
			System.out.println(encoder.encode(name.getBytes()));
		}
	}
	
	public static void decoder() throws IOException {
		BASE64Decoder decoder = new BASE64Decoder();
		while (true) {
			System.out.println("please input your content");
			String name = new BufferedReader(new InputStreamReader(System.in)).readLine();
			System.out.println(new String(decoder.decodeBuffer(name)));
		}
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics