Base64.Decoder
时间: 2024-01-06 22:03:44 浏览: 32
`Base64.Decoder`是Java中的一个类,它是在JDK 8中引入的。它用于解码Base64编码的数据。
使用`Base64.Decoder`类,你可以将Base64编码的字符串或字节数组解码为原始数据。以下是一个简单的示例:
```java
import java.util.Base64;
public class Main {
public static void main(String[] args) {
String encodedString = "SGVsbG8gV29ybGQh"; // Base64编码的字符串
// 创建Base64.Decoder对象
Base64.Decoder decoder = Base64.getDecoder();
// 解码字符串
byte[] decodedBytes = decoder.decode(encodedString);
// 将字节数组转换为字符串
String decodedString = new String(decodedBytes);
System.out.println(decodedString); // 输出: "Hello World!"
}
}
```
在上面的示例中,我们使用`Base64.getDecoder()`方法获取一个`Base64.Decoder`对象,然后使用`decode()`方法将Base64编码的字符串解码为字节数组。最后,我们将字节数组转换为字符串并打印输出。
除了解码字符串之外,`Base64.Decoder`还可以解码Base64编码的字节数组。你可以使用`decode(byte[])`方法来实现。
希望这可以回答你的问题!如果还有其他问题,请随时提问。