Java生成BASE64编码

时间:2014-04-02 11:19:27   收藏:0   阅读:574

1.所需jar包:

    BASE64Encoder.jar

2.在导包过程中,可能会出现工程不识别的情况。即:不能找到BASE64Encoder的jar包。此时,可以有两种方法解决这个问题:

    a.  只需要在project build path 中先移除JRE System Liberary, 再添加库JRE System Liberary ,重新编译后就一切正常了。

    b. Windows--->Preferences--->Java--->Compiler--->Errors/Warnings--->Deprecated and trstricted API --->Forbidden reference (access rules):--->change        to warning 

     ps:我是用方法a解决的这个问题。

3.详细代码实现如下:

package com.itRed.base64Util;

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

import sun.misc.BASE64Encoder;

public class Base64Util {

/**
* 生成Base64编码
* @param <BASE64Encoder>
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub

BASE64Encoder encoder=new BASE64Encoder();
System.out.println("please input username:");
String username=new BufferedReader(
new InputStreamReader(System.in)).readLine();
System.out.println(encoder.encode(username.getBytes()));
System.out.println("please input your password:");
String password=new BufferedReader(
new InputStreamReader(System.in)).readLine();
System.out.println(encoder.encode(password.getBytes()));
}

}

Java生成BASE64编码,布布扣,bubuko.com

原文:http://www.cnblogs.com/itred/p/3636885.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!