Sun.misc.base64decoder import exception and handling ideas

Java background save Base64 image data

use byte [] bytes = new base64decoder(). Decodebuffer (STR); Sun.misc.base64decoder needs to be introduced, but it is prompted in eclipse that this war package does not exist

It is mentioned in an article after consulting:

All along, base64 encryption and decryption use base64encoder under sun.misc package and sun.misc.base64encoder/base64decoder class of base64decoder. This class is an internal method of Sun company and has not been disclosed in Java API. It does not belong to JDK standard library. However, it is included in JDK and can be used directly. But you can’t find this class if you use it directly in eclipse and MyEclipse. “

The solution is as shown in the figure: right click Project – properties – Java build path – JRE system library – access rules – resolution, select accessible, fill in * * below and click OK

In addition, there are corresponding alternative objects and methods on the Internet, such as using

Org. Apache. Commons. Codec. Binary. Base64, etc. You can check it yourself

change to org.apache.commons.codec.binary.base64 instead

String base64Code = request.getParameter("base64Code");
Base64 base64 = new Base64();
byte[] bytes = base64.decodeBase64(new String(base64Code).getBytes());

Personal test, the effect is the same

Similar Posts: