java实现base64的解码
时间: 2023-10-15 14:30:51 浏览: 78
Java中可以使用Base64类来实现Base64解码。具体步骤如下:
1. 导入java.util.Base64类库:
```java
import java.util.Base64;
```
2. 调用Base64类的getDecoder()方法获取解码器:
```java
Base64.Decoder decoder = Base64.getDecoder();
```
3. 调用解码器的decode()方法对Base64字符串进行解码:
```java
byte[] decodedBytes = decoder.decode(base64String);
```
完整代码示例:
```java
import java.util.Base64;
public class Base64DecoderExample {
public static void main(String[] args) {
String base64String = "SGVsbG8gV29ybGQh";
Base64.Decoder decoder = Base64.getDecoder();
byte[] decodedBytes = decoder.decode(base64String);
String decodedString = new String(decodedBytes);
System.out.println(decodedString);
}
}
```
输出结果为:
```
Hello World!
```
阅读全文