Reasons and solutions why sun.misc.BASE64Encoder cannot be used directly in Eclipse

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

 

[java]  view plain copy  
 
  1. package com.test;  
  2.   
  3. import sun.misc.BASE64Encoder;  
  4. import sun.misc.BASE64Decoder;  
  5.   
  6. public class Base64Util {  
  7.   
  8.     public static void main(String[] args) throws Exception {  
  9.         String srcStr =  "BASE64 encoding test";  
  10.         String resultStr = new BASE64Encoder().encode(srcStr.getBytes());  
  11.         System.out.println(resultStr);  
  12.         String plainText = new String(new BASE64Decoder().decodeBuffer(resultStr));   
  13.         System.out.println(plainText);  
  14.     }  
  15. }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324833221&siteId=291194637