在进行拍照上传时遇到需要根据文件获取Base64字符串的功能时需要导入sun.misc.BASE64Encoder和sun.misc.BASE64Encoder 对应的rt.jar,该怎么办呢?
其实这个是 Sun 的专用 API , rt.jar 是jre 中自带的 jar 包,
我们以eclipse为例,进行如下操作就可以完成jar的导入。
右键项目->属性->Java bulid path->jre System Library->(下拉列表第一个)access rules->resolution选择accessible,下面填上** 点击确定即。
在MyEclipse中编写Java代码时,用到了BASE64Decoder,import sun.misc.BASE64Decoder;但是Eclipse提示:
Access restriction: The type BASE64Decoder is not accessible due to restriction on required library C:\Program
files\java\jre6\lib\rt.jar
Access restriction : The constructor BASE64Decoder() is not accessible due to restriction on required library C:\Program files\java\jre6\lib\rt.jar
解决方式1(推荐):
仅仅须要在project build path中先移除JRE System Library,再加入库JRE System Library,又一次编译后就一切正常了。
解决方式2:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings ->
Deprecated and trstricted API -> Forbidden reference (access rules): -> change to warning
网友评论