1. Why can't sun.misc.BASE64Encoder and sun.misc.BASE64Decoder be used directly in Eclipse?
Because sun.misc.BASE64Encoder and sun.misc.BASE64Decoder are Sun proprietary APIs that may be removed in a future release, their use is deprecated. Therefore, it cannot be used directly in Eclipse, but you can directly use a text editor to write code, and then use javac to compile, and there is no problem with java to execute.
2. You can use the following settings in Eclipse
Right click on the project --> Properties --> Java Build Path --> Click on JRE System Library --> Click on Access rules --> Edit --> Add --> Resolution select Accessible --> Rule Pattern fill in** --> OK
3. The following is a simple test program
- package com.test;
- import sun.misc.BASE64Encoder;
- import sun.misc.BASE64Decoder;
- public class Base64Util {
- public static void main(String[] args) throws Exception {
- String srcStr = "BASE64 encoding test";
- String resultStr = new BASE64Encoder().encode(srcStr.getBytes());
- System.out.println(resultStr);
- String plainText = new String(new BASE64Decoder().decodeBuffer(resultStr));
- System.out.println(plainText);
- }
- }