The type BASE64Encoder is not accessible问题(转)

来源:互联网 发布:知乎回答问题如何匿名 编辑:程序博客网 时间:2024/06/02 05:51
在Eclipse中编写Java代码时,用到了BASE64Decoder,import sun.misc.BASE64Decoder;可是Eclipse提示:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
 Access restriction: The type BASE64Encoder is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar
 Base64Encoder cannot be resolved to a type

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

C:\Program Files\Java\jre6\lib\rt.jar是BASE64Encoder类所在的jar包

BASE64Encoder的使用:

BASE64Encoder encoder = new BASE64Encoder();
  System.out.println("please input a string:");
  String str = new BufferedReader(
     new InputStreamReader(System.in))
     .readLine();
  System.out.println(encoder.encode(str.getBytes()));//输出str字符串经过BASE64Encoder编码后的BASE64编码


转自:

http://blog.sina.com.cn/s/blog_69b6a7c60100rasl.html

原创粉丝点击