sun.misc.BASE64Decoder and sun.misc.BASE64Encoder are not available [solution]

sun.misc.BASE64Decoder and sun.misc.BASE64Encoder are not available [solution]


Dingdu! Here is the compilation of Xiao Ah Woo's study course materials. A good memory is not as good as a bad pen. Today is also a day to make progress. Let's advance together!
Insert picture description here

1. Problem description

A recent project experiment found that the project had an error after importing the tool program, and it was found that sun.misc.BASE64Decoder and sun.misc.BASE64Encoder were not available, and the corresponding class could not be found.

Cause Analysis

After surfing, I found that lib\tools.jar in JDK and lib\rt.jar in JRE have been deleted from Java SE 9, which means that the jdk after version 1.8 no longer supports sun.misc.BASE64Decoder and sun.misc.BASE64Encoder .
The classes and resources available in these JARs are now stored in a named module in the lib directory in an internal format in the file. A new scheme called jrt can be used to retrieve these classes and resources from the runtime image. Applications that rely on these JAR locations will no longer work.

Two, the solution

1. Replace JDK public API

Since JDK 1.8, the JDK public API of java.util.Base64.Decoderand has been provided java.util.Base64.Encoder, which can replace the JDK internal API of sun.misc.BASE64Decoder and sun.misc.BASE64Encoder.

The official website API of java.util.Base64.Decoder:

https://docs.oracle.com/javase/9/docs/api/java/util/Base64.Decoder.html

The official website API of java.util.Base64.Encoder:

https://docs.oracle.com/javase/9/docs/api/java/util/Base64.Encoder.html

2. Switch JDK version

将JDK更换到1.8版本,即可正常使用。

Insert picture description here

Here~
Xiao Ah Woo uses this method, and it solves the problem perfectly without error!

Insert picture description here

Ending!
More course knowledge learning records will come later!

就酱,嘎啦!

Insert picture description here

Note:
Life is diligent, nothing is gained.

Guess you like

Origin blog.csdn.net/qq_43543789/article/details/109146468
Recommended